wpf - 在 WPF 中使用命令

标签 wpf model-binding

我一直在努力解决this example在 WPF 中使用命令时,我遇到了一些问题。

我已经从 nuget 安装了 MVVMLight,并且一直在尽我所能。我遇到了一些问题。

我的 View 模型:

 Class BoreModel
 {
    public ICommand Updatesql
    {
        get; internal set;
    }

    private void CreateUpdatesql()
    {
        Updatesql = new RelayCommand(UpdatesqlExecute);
    }

    private void UpdatesqlExecute()
    {
        FormSql.ProcessFormLocal(form1);
    }

    public BoreModel(string BusinessUnit, string TaskID)
    {
        CreateUpdatesql();
    }
}

我的Xaml:

    <Button Click="{Binding Path=Updatesql}" Content="Button" HorizontalAlignment="Left" Margin="206,211,0,0" VerticalAlignment="Top" Width="75"/>

背后的代码:

    public MainWindow()
    {
        DataContext = new BoreModel();
        InitializeComponent();
    }

我收到一条指向底线的错误:“‘在‘System.Windows.Data.Binding’上提供值引发了异常。’”行号“12”和行位置“17”。”

有什么想法吗?

最佳答案

您应该使用 Command 属性,而不是 Click 事件。

<Button Command="{Binding Updatesql}" ...

关于wpf - 在 WPF 中使用命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094456/

相关文章:

c# - 将文本 block 绑定(bind)到 XAML 中键的字典值?

c#/WPF openFile对话框打开两次

html - WpF Medinova 模板中的 rtl

servicestack - 为什么servicestack无法对json post请求进行模型绑定(bind)?

javascript - 多个 Json 对象未绑定(bind)到 HttpPost 上的 asp.net mvc Controller 操作

c# - XAML ContentControl 数据绑定(bind)不起作用

c# - 如何为数据绑定(bind)组合框预定义组合框项?

c# - ASP.NET MVC 无法通过绑定(bind)到复选框来发布 View 模型

c# - MVC 空查询字符串参数奇怪的行为

.net - 动态表行未通过 jquery ajax 调用更新