1

I have a list of items in WPF datagrid. As source I use ObservableCollection. One of the column is also checkbox binding to the bool property of collection. In the same window, out of the grid, I have also a button. I want the button to be disabled if there is no record with the checkbox checked = all items have the bool property set as false.

I think it wouldnt be any problem to do that in codebehind but I am trying do it in more wpf way using styles, triggers etc. But I dont know how to do this one.

4

1 回答 1

2

我建议使用 MVVM 方法,该方法涉及创建一个CommandDataBound 到Button. 如果您还没有使用 MVVM 框架,那么这里有几个。

在 Prism 中(一种可能性)DelegateCommand有一个CanExecute可以实现的委托。然后,此CanExecute方法将评估您ObservableCollection的项目并决定是否Command可以执行(启用)或不(禁用)。如果此方法返回 false,则该按钮将被禁用。

所有其他 MVVM 框架都将具有类似的Command结构。

Prism 文档中有关于此活动和其他 MVVM 相关活动的大量文档。可以在此处找到特定于命令的文档和示例。

于 2013-05-05T14:36:38.170 回答