【发布时间】:2015-07-11 22:19:53
【问题描述】:
我完全不知道是什么原因造成的。
背景:使用 Prism 框架
- 我有一个绑定到
DelegateCommand的按钮- 我打电话给
RaiseCanExecuteChanged
当我在 Visual Studio 中以调试模式启动应用程序时,一切正常。该应用程序运行良好。
当我通过 .exe 打开应用程序时,RaiseCanExecuteChanged 方法没有被调用。我不知道为什么会这样。其他人也遇到过类似的问题吗?
编辑:当我第一次通过 .exe 打开应用程序时,会调用 RaiseCanExecuteChanged(因为我在 ViewModel 的构造函数中设置了它)。但是,它再也不会被调用。
代码以备不时之需:
private readonly DelegateCommand _buttonCommand;
public ViewModel()
{
_buttonCommand = new DelegateCommand(Button, CanExecuteButton);
}
public DelegateCommand ButtonCommand
{
get { return this._buttonCommand; }
}
public void Button()
{
... do stuff ...
_buttonCommand.RaiseCanExecuteChanged();
}
public bool CanExecuteButton()
{
if (some condition)
return true;
else
return false;
}
<Button x:Name="MyButton" Content="ClickMe"
Command="{Binding ButtonCommand}">
我什至绝望了,并尝试在我的 Button 中添加一个 IsEnabled 属性,我绑定到 CanExecuteButton ... 无济于事。
【问题讨论】:
-
你能把
ButtonCommand的代码贴出来吗? -
已解决,但我不知道为什么。它现在正在工作......
标签: c# wpf mvvm prism delegatecommand