我都从头开始重建Josh Smith's CommandSink example和我的版本没有错误运行除了我的命令按钮是灰色的。我想这是因为有一些地方没有设置正确,这样永远不会设置为CanExecute = true
或在某一时刻得到的命令设置为CanExecute = false
。但是由于数据绑定本质上是在XAML中进行的,我不确定在哪里“设置命令断点”,因此我可以在什么时候看到按钮被分配了CanExecute = false或例如未分配CanExecute = true
。如何去有关MVVM调试数据绑定的问题?
基本上我有一个观点,这些命令绑定:
<UserControl.CommandBindings>
<sink:CommandSinkBinding Command="vm:CustomerViewModel.CloseCommand"/>
<sink:CommandSinkBinding Command="vm:CustomerViewModel.ShowInformationCommand"/>
</UserControl.CommandBindings>
,并在我的CustomerViewModel命令的定义如下:
public static readonly RoutedCommand CloseCommand = new RoutedCommand();
public bool CanBeClosed
{
get { return _customer.IsOpen; }
}
public void Close()
{
_customer.IsOpen = false;
this.OnPropertyChanged("CanBeClosed");
this.OnPropertyChanged("CanBeApproved");
}
但因为我的MVVM的理解,现在是你设置你的M-VM-M,运行你的应用程序,以及“获得数据绑定和正常工作”的东西。
我想我寻找的东西像“页面周期”在ASP.NET在其中步,找出当我的命令是CanExecute = true
,当他们CanExecute = false
。
一个人怎么能去调试像这样的WPF/MVVM模式在数据绑定不是在代码完成的明确,因此人们不能在传统意义上的分步调试通过?
答:
虽然this article that Gishu mentioned在一般关于如何去调试数据绑定的问题,一般回答我如何做到这一点的问题有帮助的,它并没有帮助我在我的具体情况。
对于它的价值,我想我有这个代码具体问题出做一个与约什 - 史密斯的原代码行,每行比较,发现这两条线路从CommandSinkBinding.OnCommandSinkChanged
方法中缺少的:
if (!ConfigureDelayedProcessing(depObj, commandSink))
ProcessCommandSinkChanged(depObj, commandSink);
这是重复的(至少在答案方面)?的 [http://stackoverflow.com/questions/337023/how-to-detect-broken-wpf-data-binding](http://stackoverflow.com/questions/337023/how-to-detect-broken- wpf-data-binding)你也可以在谷歌的Bea Stollnitz文章中看到同样的内容。 – Gishu 2009-04-22 15:20:22
答案部分中的链接现在已经死机:( – 2017-08-03 14:54:30