Using MvxCommand With CommandParameter binding

后端 未结 2 777
旧时难觅i
旧时难觅i 2021-01-04 12:42

I\'m trying using fire MvxCommand with CommandParameter, but faced with following problem: MyView.axml contains:



        
2条回答
  •  误落风尘
    2021-01-04 13:22

    I was doing CommandParameter coding today and you need to do couple of fixes. The axml code should contain CommandParameter='yourParameter' it looks like this:

    
    

    Even if you want to catch an Integer you still need to pass this in single quotation marks as this: CommandParameter='1234'

    In C# code the most important thing is remove MvxCommand from constructor. This should be treated as Property.

    public class MyViewModel : MvxViewModel
    {
        public MyViewModel() { }
    
        public MvxCommand MyCommand
        {
            get
            {
                return new MvxCommand(param => 
                {
                    if (param == "foo")
                    {
                        // do something
                    }
                    else if (param == "bar")
                    {
                        // do something else
                    }
                });
            }
        }
    }
    

    This was done in MvvmCross6. It should work fine with previous versions.

提交回复
热议问题