Disabling MenuItem Icon
-
Hi all, For the last couple of days I've been try to disable the MenuItem.Icon image when the MenuItem itself becomes disabled. I've implemented Style Triggers for my Toolbar icons but I can't seem to get them to work with the MenuItem icons. This is my current style definition (in my Main Menu uc):
<UserControl.Resources>
<!-- The following style causes the toolbar buttons to become dimmed when they are disabled -->
<Style TargetType="{x:Type Image}" x:Key="menuImageStyle">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuItem}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
<Setter Property="Opacity" Value="0.4" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>With this as the MenuItem itself:
<Grid>
<Menu Height="22" Name="mnuMainMenu">
<MenuItem Name="itmFile" Header="{x:Static r:ucMainMenu.itmFile}">
<MenuItem Name="itmSave" Header="{x:Static r:ucMainMenu.itmSave}" Command="ApplicationCommands.Save" InputGestureText="Ctrl+S">
<MenuItem.Icon>
<Image Name="imgSave" Source="/SCPS;component/Icons/save.ico" Height="16" Style="{StaticResource menuImageStyle}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</Grid>I found a blog posting that recommended moving farther up the element tree by using UIElement instead of MenuItem as the Ancestor Type, but that didn't work either. I did notice the following being displayed in the Output window:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.MenuItem', AncestorLevel='1''. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'Image' (Name='imgSave'); target property is 'NoTarget' (type 'Object')
Also, in trying to debug this issue, I got myself a copy of Snoop and noticed that the root element of a Context Menu is not the ApplicationRoot... Unsure as to whether or not this relates to my problem... Any thoughts? -
Hi all, For the last couple of days I've been try to disable the MenuItem.Icon image when the MenuItem itself becomes disabled. I've implemented Style Triggers for my Toolbar icons but I can't seem to get them to work with the MenuItem icons. This is my current style definition (in my Main Menu uc):
<UserControl.Resources>
<!-- The following style causes the toolbar buttons to become dimmed when they are disabled -->
<Style TargetType="{x:Type Image}" x:Key="menuImageStyle">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuItem}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
<Setter Property="Opacity" Value="0.4" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>With this as the MenuItem itself:
<Grid>
<Menu Height="22" Name="mnuMainMenu">
<MenuItem Name="itmFile" Header="{x:Static r:ucMainMenu.itmFile}">
<MenuItem Name="itmSave" Header="{x:Static r:ucMainMenu.itmSave}" Command="ApplicationCommands.Save" InputGestureText="Ctrl+S">
<MenuItem.Icon>
<Image Name="imgSave" Source="/SCPS;component/Icons/save.ico" Height="16" Style="{StaticResource menuImageStyle}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</Grid>I found a blog posting that recommended moving farther up the element tree by using UIElement instead of MenuItem as the Ancestor Type, but that didn't work either. I did notice the following being displayed in the Output window:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.MenuItem', AncestorLevel='1''. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'Image' (Name='imgSave'); target property is 'NoTarget' (type 'Object')
Also, in trying to debug this issue, I got myself a copy of Snoop and noticed that the root element of a Context Menu is not the ApplicationRoot... Unsure as to whether or not this relates to my problem... Any thoughts?Use {DyamicResource menuImageStyle} instead.
-
Use {DyamicResource menuImageStyle} instead.