是有约束力的IsEnabled可选绑定命令时? [英] Is binding IsEnabled optional when binding Command?
问题描述
我发现下面的代码:
<Button Content="_Timbres..."
Command="{Binding Path=ShowTimbresCommand}"
IsEnabled="{Binding Path=CanExecuteShowTimbresCommand}"/>
同样表现为:
behaves equally as:
<Button Content="_Timbres..."
Command="{Binding Path=ShowTimbresCommand}">
意思就是说CanExecuteShowTimbresCommand自动绑定到IsEnabled属性。
是真实的,为什么?
Meaning that the CanExecuteShowTimbresCommand is automatically bound to the IsEnabled property. Is that true and why?
推荐答案
通常控制其接受命令
将设置 IsEnabled
到假
如果命令的 CanExecute
是假
,这一切就是这么简单。
Usually controls which accept a Command
will set IsEnabled
to false
if the command's CanExecute
is false
, that's all there is to it.
的 MSDN :
命令的另一个目的是表明一个动作是否可用。 [...]一个按钮可以订阅 CanExecuteChanged 事件,如果 CanExecute 回报虚假禁止或可如果 CanExecute 回报真正
Another purpose of commands is to indicate whether an action is available. [...] A button can subscribe to the CanExecuteChanged event and be disabled if CanExecute returns false or be enabled if CanExecute returns true.
这篇关于是有约束力的IsEnabled可选绑定命令时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!