从axml获取参数到Command

时间:2013-10-17 10:03:44

标签: xamarin.android mvvmcross

AXML:

<Button  
android:id="@+id/greenButton"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Green"
local:MvxBind="Click ShowColorCommand, CommandParameter='Green'"/>

和ViewModel:

public class MainViewModel
    : MvxViewModel
{
    public ICommand ShowColorCommand
    {
        get
        {
            return new MvxCommand(() => ShowViewModel<ColorViewModel>(new { color = ??? } ));
        }
    }
}

如何从命令中的.axml('Green')中读取/使用CommandParameter?我需要在“???”

中加入什么

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:2)

使用通用MvxCommand<T>表单 - Using MvxCommand With CommandParameter binding

中有一个字符串示例
new MvxCommand<string>(param =>
  {
      if (param == "foo")               
      {
        // do something
      }
      else if (param == "bar")
      {
        // do something else
      }
  });