我一直在努力解决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/