Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF enable/disable controls

Tags:

wpf

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 for Menu items but for any WPF control?

like image 412
TheWommies Avatar asked Feb 28 '10 21:02

TheWommies


1 Answers

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 :)

like image 148
Aran Mulholland Avatar answered Nov 15 '22 06:11

Aran Mulholland