将 MvxCommand 与 CommandParameter 绑定结合使用

2023-11-22

我正在尝试用火MvxCommand 与 CommandParameter,但面临以下问题: MyView.axml 包含:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1"
        local:MvxBind="Click MyCommand, CommandParameter=foo" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2"
        local:MvxBind="Click MyCommand, CommandParameter=bar" />
</LinearLayout>

MyViewModel.cs:

public class MyViewModel : MvxViewModel
{
    public ICommand MyCommand { get; private set; }

    public MyViewModel()
    {                                    // param is null
      MyCommand = new MvxCommand<string>(param =>
      {
          if (param == "foo")               
          {
            // do something
          }
          else if (param == "bar")
          {
            // do something else
          }
      });
    }
}

但是当我检查时param变量是null.

我做错了什么?


您的代码在我的源代码树的顶部为我工作。

但这个功能才推出两周。

我的猜测是,此功能要么没有包含在您正在使用的版本中,要么存在错误。

您可以检查此绑定的调试跟踪吗?那里有什么信息吗?

  • 如果痕迹表明CommandParameter是一个未知的符号,那么我的猜测是您需要自己构建最新的源代码 - 或者等待新版本。
  • 如果跟踪显示其他内容,那么您也许可以在安装过程中修复问题。

我知道我们解决的一件事是价值转换器问题Cirrious.MvvmCross.Binding.dll based ValueConverter不只是通过覆盖Setup.ValueConverterAssemblies注册ValueConverter为此需要CommandParameter

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 MvxCommand 与 CommandParameter 绑定结合使用 的相关文章

随机推荐