我正在尝试使用带有CommandParameter的fire MvxCommand,但面临以下问题:MvxCommand with 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
}
});
}
}
但是当我检查参数变量时,发现null。
我做错了什么?
local:MvxBind="Click OnRemoveClick, CommandParameter=."
,但在执行命令时也得到了相同的“.”。请问有什么想法吗? - Mohammad Riyaz