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 (将#修改为@)