开发者

WPF enable/disable controls

When I disable a control in WPF, like say a menu item like

MenuItem aMenuItem = ...
aMenuItem.IsEnabled = false;

the text in the MenuItem is still active, that is it is not grayed out as you would expect when items are disabled.

Is there a simple way to do this not only f开发者_StackOverflow中文版or Menu items but for any WPF control?


yes by using commands. MenuItems and Buttons have a command property. a Command is an implementation of the ICommand interface which has a method called CanExecute. When can execute is called if it returns true the menutitem or button is enabled, otherwise it is greyed out.

MSDN Command overview

nice simple tutorial on setting up commands

google search :)


You can also just set the opacity of the control to 0.5 , to get the "grayed out" effect

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜