开发者

WPF MenuItem Color when set to black wont change to grey when disabled

When the top menu item foreground i开发者_Go百科s set to black and the background is set to white everything works fine for both XP and Windows 7. But we are using a main menu bar that is black and with white foreground. This causes issues in windows 7 only. Why is it that when you set a menuitem foreground to black it wont change to grey when disabled.


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

The Foreground="Black" attribute overrides the built in style trigger that is a function of IsEnabled.

To accomplish what you are looking for requires building your own style with a Trigger on IsEnabled. The following code shows how to do this in-line, although you're likely to want to pull the Style into a resources section and use it on 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>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜