WPF enable / disable controls

When I disable a control in WPF, for example, for example a menu item, for example

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

the text in MenuItem is still active, that is, it will not be grayed out, as you would expect when elements were disabled.

Is there an easy way to do this, not only for menu items, but also for any WPF control?

+4
source share
2 answers

yes using commands. Menus and buttons have a command property. The command is an implementation of the ICommand interface, which has a CanExecute method. When a call can be made, it is called if it returns true, the menu button or the button is turned on, otherwise it is inactive.

Overview of MSDN Commands

nice easy tutorial on setting up commands

google search :)

+6
source

You can also set the opacity of the control to 0.5 to get a gray effect.

-5
source

Source: https://habr.com/ru/post/1302687/


All Articles