在 xmlns clr 命名空间中找不到 EventToCommandBehavior:Prism.Behaviors

2023-12-11

我正在开发 Xamarin.Forms 项目。在 Prism 6.3 之前我使用过 6.2Corcav.Behaviors包裹。我不需要传递参数,所以效果很好。但是,在iOS项目中AppDelegate我需要运行这一行:

Corcav.Behaviors.Infrastructure.Init();

我有一个评论://添加以防止 iOS 链接器从部署的包中剥离行为程序集。

Now EventToCommand6.3版本添加了,所以我卸载了Corcav.Behaviors封装并实现了简单的例子。在 Android 中一切都很好,但 iOS ..我有一个例外:

enter image description here

我认为这是因为现在我错过了这一行:Corcav.Behaviors.Infrastructure.Init();

我的例子:

VIEW:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:v="clr-namespace:TestApp.Mobile.Views"
             xmlns:behavior="clr-namespace:Prism.Behaviors;assembly=Prism.Forms" 
             x:Class="TestApp.Mobile.Views.StartPage">
  <v:TestGrid x:Name="MainGrid">
    <v:TestGrid.Behaviors>
      <behavior:EventToCommandBehavior EventName="OnTestTapped" 
                                        Command="{Binding OnTestTappedCommand}" 
                                        EventArgsParameterPath="Foo"/>
    </v:TestGrid.Behaviors>
  </v:TestGrid>
</ContentPage>

我的自定义网格:

public class TestGrid : Grid
{
    public event EventHandler<OnTouchedEventArgs> OnTestTapped;

    public TestGrid()
    {
        var tgr = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
        tgr.Tapped += Tgr_Tapped;
        this.GestureRecognizers.Add(tgr);
    }

    private void Tgr_Tapped(object sender, EventArgs e)
    {
        OnTouchedEventArgs args = new OnTouchedEventArgs(6);
        OnTestTapped?.Invoke(sender, args);
    }
}

视图模型

public class StartPageViewModel : BindableBase
{
    private bool _canExecute;
    private ICommand onTestTappedCommand;

    public StartPageViewModel()
    {
        _canExecute = true;
    }

    public ICommand OnTestTappedCommand
    {
        get
        {
            return onTestTappedCommand ?? (onTestTappedCommand = 
                    new Command<int>((foo) => HandleEvent(foo), 
                                     (foo) => CanExecute(foo)));
        }
    }

    public async void HandleEvent(int a)
    {
        _canExecute = false;
        Status = $"Working with parameter={a}...";
        Debug.WriteLine("Test with param=" + a);
        await Task.Delay(5000);
        Status = "Done";
        _canExecute = true;
    }

    public bool CanExecute(int a)
    {
        return _canExecute;
    }
}    

..和我的自定义EventArgs:

public class OnTouchedEventArgs : EventArgs
{
    public int Foo { get; set; }

    public OnTouchedEventArgs(int foo)
    {
        Foo = foo;
    }
}   

我在 Android 上 100% 工作,在 iOS 上不行。

问题: 我怎样才能在Infrastruction.Init中Prism.Behaviors?

EDIT:

我认为错误可能比我想象的要多......正如你在我的 ViewModel 中看到的,我正在使用ICommand and Command班级来自Xamarin.Forms命名空间:

    private ICommand onTestTappedCommand;        
    public ICommand OnTestTappedCommand
    {
        get
        {
            return onTestTappedCommand ?? (onTestTappedCommand = 
                    new Command<int>((foo) => HandleEvent(foo), 
                                     (foo) => CanExecute(foo)));
        }
    }

它可以在 Android 上运行,但是..当我更改为DelegateCommand:

        return onTestTappedCommand ?? (onTestTappedCommand = 
                new DelegateCommand<int>((foo) => HandleEvent(foo), 
                                 (foo) => CanExecute(foo)));

安卓系统则不太好用。然后我有一个运行时异常:

未处理的异常:System.Reflection.TargetInitationException: 调用目标已引发异常。

并且..该项目符合要求,但在 Start.xaml.cs 中我有一个错误:

InitializeComponent() 在当前上下文中不存在

附言。请帮助我,请不要告诉我清除解决方案/删除 bin obj 文件夹...它不起作用。


不需要初始化。从例外情况来看,您所展示的我的建议是进行彻底的清理和重建。确保您的所有文件obj and bin文件夹被删除。

视图模型

public DelegateCommand<string> PersonSelectedCommand => new DelegateCommand<string>(OnPersonSelectedCommandExecuted);

public ObservableRangeCollection<string> People { get; set; }

void OnPersonSelectedCommandExecuted(string name)
{
    _pageDialogService.DisplayAlertAsync("Person Selected", name, "Ok" );
}

View

<ListView ItemsSource="{Binding People}">
    <ListView.Behaviors>
        <behaviors:EventToCommandBehavior Command="{Binding PersonSelectedCommand}" 
                                          EventName="ItemTapped"
                                          EventArgsParameterPath="Item" />
    </ListView.Behaviors>
</ListView>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 xmlns clr 命名空间中找不到 EventToCommandBehavior:Prism.Behaviors 的相关文章

随机推荐

  • Android:自定义相机拍摄的图像太暗

    在我的应用程序中 我必须拍摄自定义活动的照片 我实现了所有功能并且可以保存我的照片 但在某些设备中它们太暗了 我有这段代码 但它对我没有帮助 Parameters params mCamera getParameters if params
  • Clock() - C 函数的执行时间

    我正在尝试测量 C 代码块的执行时间 我的代码中有类似这样的内容 clock t begin end double time spent begin clock ATL dsymv 122 n alfa A n X 1 beta Y 1 e
  • 在 powershell 中聚焦 IE 窗口

    My code ie new object com InternetExplorer Application ie navigate http localhost ie visible true ie fullscreen true 但是全
  • 如何在 RMI 方法的参数中传递对象?

    我正在尝试在 RMI 方法中添加参数 当我添加例如String一切正常 但我不确定是否可以传递我创建的对象 我是 RMI 新手 所以我的代码非常简单 HelloIF public interface HelloIF extends Remo
  • 尝试使用 JavaScript 从 azure 获取访问令牌时无法加载响应数据

    我想为我在 azure 上注册的应用程序获取访问令牌 为此 我编写了一段代码来访问其余 API 这是我的代码
  • 数据透视表字段显示除空白之外的所有内容

    我需要在刷新后更新数据透视过滤器以选择除blank 这里的其他答案利用 ShowAllItems方法对我不起作用 因为它也会显示没有数据的项目 下面的枢轴选项Display 我尝试使用在另一个问题上找到的另一个解决方案 PivotItems
  • 通过自定义协议符合 MKAnnotation 协议

    我想轻松地在地图上获取 2 个或更多不同的对象类型 Swift 2 0 我想使用协议 我创建了一个这些对象也需要遵守的协议 我假设现在任何符合 PinProtocol 的项目本质上与 MKAnnotation 相同 只是更多 protoco
  • Android Google Play / Drive Api

    您好 我正在使用 Google Drive Api 通过 AppDataFolder 工具来存储数据库 我有一个测试应用程序在一台设备上成功运行 我能够上传 更新 删除 下载数据库文件并将其重新集成到程序中 没有任何问题 我遇到的问题是 当
  • 正则表达式在javascript中匹配反向组

    我想匹配的字符串don t have abc def or ghi 相反的情况很简单 abc def ghi 我该如何扭转这种情况 我不想 abc def ghi 因为那里会有更多的 逻辑 如果这就是它的作用的话 如何逆转整场小组赛 或无论
  • 为什么我的闰年算法不起作用(Java)? [复制]

    这个问题在这里已经有答案了 这是我所拥有的 Scanner input new Scanner System in System out print Enter a year int Year input nextInt System ou
  • 从sql server中的表中分割逗号分隔值

    我有一个SQL table其中有多少条记录 我想知道其中有多少个名字以及一个名字在其中出现的时间 表名Mst Name john smith alax rock smith alax sira john rock rock sira 我想知
  • C#:使用单独的线程填充 UI

    我试图从我收到的申请中找出一些意义 以便追踪错误的根源 有一些代码 此处进行了简化 创建了四个线程 这些线程依次填充主窗体上的列表视图 每个方法从数据库获取数据并从资源 dll 检索图形 以便直接填充图像列表和列表视图 从我在这里读到的内容
  • Ubuntu 上的 R BayesVarSel 安装

    我正在尝试安装BayesVarSel封装在一个ubuntu12盒上AWS EC2 它在我的 Windows 7 机器上运行良好 R 2 15 1 I ve attached a screenshot of the error message
  • 适用于 Objective C 的 Android NDK

    我想使用 Android NDK 访问 Objective C 代码 可以吗 有没有办法访问现有的 Objective C 代码 现在 是的 UPDATE 可分配已死 Try 可适配的SDK or 水晶SDK 两者都是基于Android N
  • Bootstrap 3 中的堆叠选项卡

    我正在尝试使用 Bootstrap 3 中的 Tab jquery 插件实现左对齐堆叠选项卡 其中选项卡垂直呈现在选项卡内容的左侧 而不是顶部 当我尝试以下操作时 ul class nav nav tabs nav stacked li a
  • Java中如何从HTML文件中获取值?

    我需要从 HTML 文件中获取一个值 下面示例中的 abc 如下所示
  • 查找元素中未包含在 html 标签中的文本并将其用

    括起来

    div class menu content h3 Lorem Ipsum h3 TEXT THAT NEEDS TO BE WRAPPED ul li List Item 1 li ul div 我得到了上面的代码 它是自动生成的 所以我
  • ReaderWriterLockSlim 是正确的选择吗?

    我正在为 Windows Azure 中运行的应用程序编写一个全局错误处理程序 记录器 当应用程序中发生错误时 将执行许多需要原子发生的操作 我需要防止在前一个错误完成之前记录错误 同时 我希望根据需要读取日志 我最初的想法是使用监视器 锁
  • Android中Looper、Handler、MessageQueue三者之间的关系是什么?

    我已经检查了官方 Android 文档 指南Looper Handler and MessageQueue 但我无法得到它 我是 Android 新手 对这些概念非常困惑 A Looper是一个消息处理循环 它读取并处理来自MessageQ
  • 在 xmlns clr 命名空间中找不到 EventToCommandBehavior:Prism.Behaviors

    我正在开发 Xamarin Forms 项目 在 Prism 6 3 之前我使用过 6 2Corcav Behaviors包裹 我不需要传递参数 所以效果很好 但是 在iOS项目中AppDelegate我需要运行这一行 Corcav Beh