微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MVVM 灯不会创建 ViewLocator

如何解决MVVM 灯不会创建 ViewLocator

我目前正在尝试创建一个 mvvm Wpf 应用程序,我将 MvvmLight 添加到我的项目中以帮助我(并遵循教程),但是当我添加它(版本 5.4.1.1)时,它没有创建 viewmodellocator 文件。 我尝试使用此链接我的 wpf 视图,但是当我尝试使用基本的 RelayCommand(绑定到显示消息框的中继命令的按钮)时,telaycommand 不会触发(但不会抛出错误消息)

    <Page.DataContext>
         <vm:GoPageviewmodel/>
   </Page.DataContext>

按钮:

<Button x:Name="Button" Grid.Column="0" Grid.Row="0"
            Command="{Binding OnButtonClickedCommand}" Content="Bouton"
            Background="red" FontSize="30"/>

还有命令:

using galaSoft.MvvmLight.CommandWpf;

 public RelayCommand OnButtonClickedCommand { get; private set; }
    private bool CanButtonClick()
    {
        //e.CanExecute = true;
        return true;
    }
    private void ExecuteOnButtonClicked()
    {
        MessageBox.Show($"The command was invoked ");
        Console.WriteLine("It works");
    }

视图模型构造函数中的实例化:

 this.OnButtonClickedCommand = new RelayCommand(ExecuteOnButtonClicked,CanButtonClick);

我做错了吗?或者我该怎么做才能触发命令?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。