WPF MenuItem Color when set to black does not change to gray if disabled

When the top menu item of the top menu is set to black and the background is set to white, everything works fine for both XP and Windows 7. But we use the main menu bar, which is black and has a white foreground. This causes problems only in Windows 7. Why, when setting the menuitem foreground parameter to black, it does not change to gray when disabled.

+4
source share
1 answer

I ran into the same issue with Windows XP and 7.

The Foreground = "Black" attribute overrides the inline style trigger, which is an IsEnabled function.

To accomplish what you are looking for, you need to create your own style with Trigger on IsEnabled. The following code shows how to do this in a line, although you probably want to display the style in the resource section and use it in all of your menu items.

<MenuItem Header="My Item" IsEnabled="{Binding MyItemEnabled}"> <MenuItem.Style> <Style TargetType="{x:Type MenuItem}"> <Setter Property="Foreground" Value="Black"/> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="Gray"/> </Trigger> </Style.Triggers> </Style> </MenuItem.Style> </MenuItem> 
+4
source

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


All Articles