棱镜按钮单击命令

时间:2018-12-12 16:13:23

标签: mvvm xamarin.forms prism

我尝试通过“行为”命令打开“抽屉”菜单(“融合”控件)

Xaml

<Button x:Name="hamburgerButton" 
                                HeightRequest="50" WidthRequest="50" 
                                HorizontalOptions="Start" FontSize="20"
                                BackgroundColor="#1aa1d6" >
                            <Button.Behaviors>
                                <b:EventToCommandBehavior EventName="Clicked" 
                                      Command="{Binding HamburgerButton}" />
                            </Button.Behaviors>

VM CS

    public DelegateCommand HamburgerButton { get; private set; }   
 public QuickPartViewModel(INavigationService navigationService)
{ 
    HamburgerButton = new DelegateCommand(HamburgerButton_Clicked);
}
    public void HamburgerButton_Clicked(object sender, EventArgs e)
            {            
                navigationDrawer.ToggleDrawer();
            }

如果HamburgerButton_Clicked(对象发送方,EventArgs e)带有参数,则我有错误-//聚合:无法从“方法组”转换为操作

如果我要删除Argumments,它将无法正常工作

1 个答案:

答案 0 :(得分:0)

您想得太多。只需将命令绑定到按钮即可。

在页面中:

<Button Command="{Binding HamburgerCommand}" />

在视图模型中:

public QuickPartViewModel()
{ 
    HamburgerCommand = new DelegateCommand(OnHamburger);
}

public DelegateCommand HamburgerCommand { get; }   

private void OnHamburger()
{            
     navigationDrawer.ToggleDrawer();
}

尝试the docs ...