是有约束力的IsEnabled可选绑定命令时? [英] Is binding IsEnabled optional when binding Command?

查看:223
本文介绍了是有约束力的IsEnabled可选绑定命令时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现下面的代码:

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆