【问题标题】:MvxCommand With CommandParameter binding to fieldMvxCommand 与 CommandParameter 绑定到字段
【发布时间】:2015-09-10 14:25:06
【问题描述】:

我正在尝试使用火 MvxCommand 和 CommandParameter:

   <Mvx.MvxListView
   style="@style/MyList"
   local:MvxBind="ItemsSource Items;"
   local:MvxItemTemplate="@layout/itemfavorite" />

这是我在ViemModel的财产:

    public List<Data> Items
    {
        get { return _items; }
        set
        {
            _items = value;
            RaisePropertyChanged(() => Items);
        }
    }

这是我的model:

public class Data
{
   public int Id{get;set;}
   public string Name {get;set;}
   public ICommand Action {get;set;}
}

这是我的command(在数据中使用):

    public ICommand MyCommand
    {
        get
        {
            return new MvxCommand<int>(async (id) =>
            {
               .....
            }
    }

这是我的MvxItemTemplate: ……

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start"
    android:layout_margin="10dp"
    local:MvxBind="Click Action,CommandParameter=Id"/>

如果我使用“CommandParameter=Id” - 我会得到 unhandle 异常。 “CommandParameter=1” - 这是工作。但我需要传递一个 CommandParameter 值字段 ID。有可能吗?

【问题讨论】:

    标签: android exception binding xamarin mvvmcross


    【解决方案1】:

    CommandParameter 的值是一个静态 值。不幸的是,您不能使用属性名称作为命令参数传递。

    你遇到了一个异常,因为 Mvx 试图将 string "Id" 转换为 int。

    您可以简单地在命令处理程序中使用它,而不是传递 Id。

    public ICommand MyCommand
    {
        get
        {
            return new MvxCommand(async () =>
            {
               // use Id here
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-18
      • 2011-08-17
      • 1970-01-01
      • 2013-09-22
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 2010-12-17
      相关资源
      最近更新 更多