locked
Setting menu foreground color to black when default TextBlock color is white. RRS feed

  • Question

  • I am working on an application where the UI is styled to have white text on dark background theme, this is with the exception of the menu.

    To reduce the amount of style tags the developers need to set, the common controls have had the default style changed to match the desired theme. This means that the textblock foreground has been set to white, and the background to blue. This works reasonably well. However, we want to keep the menus as black text on a light background. Unfortunately, I cannot find a way of getting this to work.

    I have tried the following
     
    1. Creating a new local style for the menu and applying it.

    2. Creating a new default style for the menu and menuitems.

    <Style TargetType="MenuItem">
        <Setter Property="Foreground" Value="Red"/>
    </Style>


    3. Changing the MenuTextBrushKey value.

    <SolidColorBrush x:Key="{x:Static SystemColors.MenuTextBrushKey}" Color="Red"/>

    These strategies successfully change the color of the menu text unless the the default textblock foreground color is changed, at which point all fail.

    Surely there should be some way of making the local styles override the global style. Isn't this how it's meant to work?



     

    Thursday, June 18, 2009 12:20 PM

All replies

  • Hi,

     

    Could you please provide a simplified and ready-to-run sample for us to repro your project? So as to we can have clear idea of where you are having issues.

     

    Thanks.


    Jim Zhou -MSFT
    Wednesday, June 24, 2009 1:24 PM
  • Ok, create a basic WPF application:

    In App.xaml, inside Application.Resources:
    <!-- Comment out this style -->
    <!-- <Style x:Key="{x:Type TextBlock}" TargetType="{x:Type TextBlock}">
    <Setter Property="Foreground" Value="White"></Setter>
    <Setter Property="Background" Value="Black"></Setter>
    </Style> -->
    <!-- End -->
    <Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}"> <Setter Property="Foreground" Value="DarkRed"></Setter> <Setter Property="Background" Value="Salmon"></Setter> </Style>

     

     

     

    Inside body of Window1.xaml

        <Window.Resources>
            <Style x:Key="LocalMenuItemStyle" TargetType="{x:Type MenuItem}">
                <Setter Property="Foreground" Value="DarkBlue"></Setter>
                <Setter Property="Background" Value="LightBlue"></Setter>
            </Style>
        </Window.Resources>
        
        <DockPanel>
            
            <Menu DockPanel.Dock="Top" Background="PaleGreen" Foreground="DarkGreen">
                
                <MenuItem Header="File - Local Properties (Greens)" Background="PaleGreen" Foreground="DarkGreen">
                    <MenuItem Header="Open" Background="PaleGreen" Foreground="DarkGreen">
                        <MenuItem Header="A File" Background="PaleGreen" Foreground="DarkGreen"/>
                    </MenuItem>
                    <MenuItem Header="Close" Background="PaleGreen" Foreground="DarkGreen"/>
                    <MenuItem Header="Export" Background="PaleGreen" Foreground="DarkGreen"/>
                </MenuItem>
                
                <MenuItem Header="Tools - Local MenuItem Style (Blue)" Style="{StaticResource LocalMenuItemStyle}">
                    <MenuItem Header="Options" Style="{StaticResource LocalMenuItemStyle}">
                        <MenuItem Header="Option 1" Style="{StaticResource LocalMenuItemStyle}"/>
                    </MenuItem>
                </MenuItem>
    
                <MenuItem Header="Help - Default MenuItem Styles (Red)">
                    <MenuItem Header="Topics">
                        <MenuItem Header="Topic 1"/>
                        <MenuItem Header="Topic 2"/>
                    </MenuItem>
                </MenuItem>
            </Menu>
            <StackPanel>
                <TextBlock> Default, desired style for a textblock is white text on a black background </TextBlock>
            </StackPanel>
        </DockPanel>
    When you run the example, you should see a menu with different colours set, depending on what style is in use or which local properties are set. If you then uncomment the default textblock style in App.Resources, all the local foreground / background settings within the area of the menu text are overidden by the textblock style (white on black). NB the glyphs are still correct.

    So how do you reset them to overcome the effects of the default TextBlock style?

    (NB I have also tried creating a full menuitem template, using an example from MSDN, this does not work either).

    Sorry about the formatting. Also, wasn't able to attach the project zipped up, so have posted the xaml.

    Thanks,

    Max



     

    • Edited by Max Palmer Thursday, June 25, 2009 3:39 PM
    Thursday, June 25, 2009 3:37 PM
  • Hi,

     

    -->So how do you reset them to overcome the effects of the default TextBlock style?

     

    You could find something like the following in the default template of MenuItem.

    <ContentPresenter

                RecognizesAccessKey="True"

                Content="{TemplateBinding HeaderedContentControl.Header}"

                ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"

                ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}"

                ContentSource="Header"

                Margin="{TemplateBinding Control.Padding}"

                Grid.Column="1" />

     

    As you can see from above, the Content property of ContentPresenter bind to the Header property of MenuItem.  If you just set a string like “header” to the Header property of MenuItem, the ContentPresenter will generate a TextBlock to hold the header. You can use some tools like Snoop to confirm this. So when you set a a implicit(a key that matches the type of the element) style for TextBlock in App.xaml file, this style will be applied to all TextBlock throughout the application.(Of course, you can use other approaches with higher precedence to override the implicit style) So you see all TextBlocks with black background and white foreground.

     

    -->(NB I have also tried creating a full menuitem template, using an example from MSDN, this does not work either).

     

    I guess you  use a ContentPresenter inside the template as a content place holder. If so, this case is just like the above one. TextBlock is generated automatically to create visual representation in you MenuItem.

     

    Any additional things unclear, please feel free to feedback. 

    Thanks.


    Jim Zhou -MSFT
    Friday, June 26, 2009 7:19 AM
  • Can you define default textblock style inside your menu resources? 
    Friday, June 26, 2009 7:29 AM
  • Sirga,

    Good idea. Unfortunately defining a local textblock style doesn't seem to work, either locally or in the resources of the default style for the MenuItem. Will try Jim's suggestion next.

    Thanks for the reply.

    Max
    Friday, June 26, 2009 8:15 AM
  • What interesting is that at design time all work as expected...
    Friday, June 26, 2009 9:11 AM
  • Yes, I noticed that. It's driving me mad and am starting to think it is a bug. The default textblock's settings seem immutable when it comes to menus! Currently trying to set a new ContentPresenterTemplate, but am still not getting the result I want.
    Friday, June 26, 2009 9:14 AM
  • Not only menus. I noticed the same behavior with other content controls, like buttons for example. Once defined default style for textblock it cannot be overwritten.
    Friday, June 26, 2009 9:48 AM
  • I thinking that problem is such as finding of default styles starting from application scope. So it found and applying.
    Tuesday, June 30, 2009 9:51 AM
  • Hi Sirga,

    Thanks for the replys. I have managed to reset the menu colors by defining the ContentTemplate(s) in the default menu implementation (all four of them). You also need to change the style on the shortcut key section of the menu. This does the job at the moment.

    Rather lengthy template:

        <!-- Default TextBlock style -->    <Style x:Key="{x:Type TextBlock}" TargetType="{x:Type TextBlock}">         
    <Setter Property="Foreground" Value="White"></Setter> <Setter Property="Background" Value="Black"></Setter> </Style> <!-- New menu style to reset colours --> <Style TargetType="{x:Type AccessText}" x:Key="MenuAccessText"> <Setter Property="Background" Value="Transparent"></Setter> </Style> <Style TargetType="{x:Type TextBlock}" x:Key="MenuTextBlock"> <!--<Setter Property="Foreground" Value="Black"></Setter>--> <Setter Property="Background" Value="Transparent"></Setter> </Style> <!-- New menu style to reset colours, derived from default style --> <LinearGradientBrush x:Key="MenuItemSelectionFill" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#34C5EBFF" Offset="0"/> <GradientStop Color="#3481D8FF" Offset="1"/> </LinearGradientBrush> <Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Grid SnapsToDevicePixels="true"> <Rectangle x:Name="Bg" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="2" RadiusY="2"/> <Rectangle x:Name="InnerBorder" RadiusX="2" RadiusY="2" Margin="1"/> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" MinWidth="24" Width="Auto"/> <ColumnDefinition Width="4"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="37"/> <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/> <ColumnDefinition Width="17"/> </Grid.ColumnDefinitions> <ContentPresenter x:Name="Icon" Margin="1" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon"/> <Border x:Name="GlyphPanel" Margin="1" Width="22" Height="22" Visibility="Hidden" Background="#E6EFF4" BorderBrush="#CDD3E6" BorderThickness="1" CornerRadius="3"> <Path x:Name="Glyph" Fill="#0C12A1" FlowDirection="LeftToRight" Width="9" Height="11" Data="{StaticResource Checkmark}"/> </Border> <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="2" ContentSource="Header" RecognizesAccessKey="True"> <ContentPresenter.ContentTemplate> <DataTemplate> <AccessText Style="{StaticResource MenuAccessText}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Header}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Foreground}" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = IsEnabled}"/> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> <TextBlock Margin="{TemplateBinding Padding}" Style="{StaticResource MenuTextBlock}" Grid.Column="4" Text="{TemplateBinding InputGestureText}"/> </Grid> </Grid> <ControlTemplate.Triggers> <Trigger Property="Icon" Value="{x:Null}"> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsChecked" Value="true"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsHighlighted" Value="true"> <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MenuItemSelectionFill}"/> <Setter Property="Stroke" TargetName="Bg" Value="#8071CBF1"/> <Setter Property="Stroke" TargetName="InnerBorder" Value="#40FFFFFF"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="#FF9A9A9A"/> <Setter Property="Background" TargetName="GlyphPanel" Value="#EEE9E9"/> <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#DBD6D6"/> <Setter Property="Fill" TargetName="Glyph" Value="#848589"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <LinearGradientBrush x:Key="MenuItemPressedFill" EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#28717070" Offset="0"/> <GradientStop Color="#50717070" Offset="0.75"/> <GradientStop Color="#90717070" Offset="1"/> </LinearGradientBrush> <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}"> <Setter Property="ClickMode" Value="Hover"/> <Setter Property="MinWidth" Value="0"/> <Setter Property="MinHeight" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RepeatButton}"> <DockPanel SnapsToDevicePixels="true" Background="Transparent"> <Rectangle x:Name="R1" Fill="Transparent" Width="1" DockPanel.Dock="Right"/> <Rectangle x:Name="B1" Fill="Transparent" Height="1" DockPanel.Dock="Bottom"/> <Rectangle x:Name="L1" Fill="Transparent" Width="1" DockPanel.Dock="Left"/> <Rectangle x:Name="T1" Fill="Transparent" Height="1" DockPanel.Dock="Top"/> <ContentPresenter x:Name="ContentContainer" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center"/> </DockPanel> <ControlTemplate.Triggers> <Trigger Property="IsPressed" Value="true"> <Setter Property="Fill" TargetName="R1" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/> <Setter Property="Fill" TargetName="B1" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/> <Setter Property="Fill" TargetName="L1" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/> <Setter Property="Fill" TargetName="T1" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/> <Setter Property="Margin" TargetName="ContentContainer" Value="3,3,1,1"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry> <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter"/> <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry> <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}"> <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/> <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ScrollViewer}"> <Grid SnapsToDevicePixels="true"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Border Grid.Column="0" Grid.Row="1"> <ScrollContentPresenter Margin="{TemplateBinding Padding}"/> </Border> <RepeatButton Style="{StaticResource MenuScrollButton}" Focusable="false" Grid.Column="0" Grid.Row="0" Command="{x:Static ScrollBar.LineUpCommand}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"> <RepeatButton.Visibility> <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="0"> <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/> </MultiBinding> </RepeatButton.Visibility> <Path Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" Data="{StaticResource UpArrow}"/> </RepeatButton> <RepeatButton Style="{StaticResource MenuScrollButton}" Focusable="false" Grid.Column="0" Grid.Row="2" Command="{x:Static ScrollBar.LineDownCommand}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"> <RepeatButton.Visibility> <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="100"> <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/> <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/> </MultiBinding> </RepeatButton.Visibility> <Path Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" Data="{StaticResource DownArrow}"/> </RepeatButton> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" TargetType="{x:Type ContentControl}"> <Border Background="#F5F5F5" BorderBrush="#FF959595" BorderThickness="1"> <Grid> <Rectangle Fill="#F1F1F1" RadiusX="2" RadiusY="2" HorizontalAlignment="Left" Margin="2" Width="28"/> <Rectangle Fill="#E2E3E3" HorizontalAlignment="Left" Margin="30,2,0,2" Width="1"/> <Rectangle Fill="White" HorizontalAlignment="Left" Margin="31,2,0,2" Width="1"/> <ContentPresenter Margin="1,0" Grid.ColumnSpan="2"/> </Grid> </Border> </ControlTemplate> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Grid SnapsToDevicePixels="true"> <Rectangle x:Name="OuterBorder" RadiusX="2" RadiusY="2"/> <Rectangle x:Name="Bg" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="1" RadiusY="1" Margin="1"/> <Rectangle x:Name="InnerBorder" Margin="2"/> <DockPanel> <ContentPresenter x:Name="Icon" Margin="4,0,6,0" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon"/> <Path x:Name="GlyphPanel" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" VerticalAlignment="Center" Visibility="Collapsed" Data="{StaticResource Checkmark}"/> <!-- ************************************************ Here ********************************************** --> <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True"> <ContentPresenter.ContentTemplate> <DataTemplate> <AccessText Style="{StaticResource MenuAccessText}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Header}" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = IsEnabled}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Foreground}"/> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> </DockPanel> <Popup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="1" IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-1" Focusable="false"> <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent"> <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}"> <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true"> <ItemsPresenter Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle"/> </ScrollViewer> </ContentControl> </Microsoft_Windows_Themes:SystemDropShadowChrome> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSuspendingPopupAnimation" Value="true"> <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/> </Trigger> <Trigger Property="Icon" Value="{x:Null}"> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsChecked" Value="true"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"> <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/> <Setter Property="Color" TargetName="Shdw" Value="#71000000"/> </Trigger> <Trigger Property="IsHighlighted" Value="true"> <Setter Property="Stroke" TargetName="Bg" Value="#90717070"/> <Setter Property="Stroke" TargetName="OuterBorder" Value="#50FFFFFF"/> <Setter Property="Stroke" TargetName="InnerBorder" Value="#50FFFFFF"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="true"> <Setter Property="Stroke" TargetName="Bg" Value="#E0717070"/> <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MenuItemPressedFill}"/> <Setter Property="Stroke" TargetName="InnerBorder" Value="#50747272"/> </Trigger> <Trigger Property="IsSubmenuOpen" Value="true"> <Setter Property="Stroke" TargetName="Bg" Value="#E0717070"/> <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MenuItemPressedFill}"/> <Setter Property="Stroke" TargetName="InnerBorder" Value="#50747272"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="#FF9A9A9A"/> <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Grid SnapsToDevicePixels="true"> <Rectangle x:Name="OuterBorder" RadiusX="2" RadiusY="2"/> <Rectangle x:Name="Bg" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="1" RadiusY="1" Margin="1"/> <Rectangle x:Name="InnerBorder" Margin="20"/> <DockPanel> <ContentPresenter x:Name="Icon" Margin="4,0,6,0" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon"/> <Path x:Name="GlyphPanel" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" VerticalAlignment="Center" Visibility="Collapsed" Data="{StaticResource Checkmark}"/> <!-- ******************************************* Here *********************************************** --> <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True"> <ContentPresenter.ContentTemplate> <DataTemplate> <AccessText Style="{StaticResource MenuAccessText}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Header}" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = IsEnabled}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Foreground}"/> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> </DockPanel> </Grid> <ControlTemplate.Triggers> <Trigger Property="Icon" Value="{x:Null}"> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsChecked" Value="true"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsHighlighted" Value="true"> <Setter Property="Stroke" TargetName="Bg" Value="#90717070"/> <Setter Property="Stroke" TargetName="OuterBorder" Value="#50FFFFFF"/> <Setter Property="Stroke" TargetName="InnerBorder" Value="#50FFFFFF"/> </Trigger> <Trigger Property="IsKeyboardFocused" Value="true"> <Setter Property="Stroke" TargetName="Bg" Value="#E0717070"/> <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MenuItemPressedFill}"/> <Setter Property="Stroke" TargetName="InnerBorder" Value="#50747272"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="#FF9A9A9A"/> <Setter Property="Fill" TargetName="GlyphPanel" Value="#848589"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry> <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}"> <Grid SnapsToDevicePixels="true"> <Rectangle x:Name="Bg" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1" RadiusX="2" RadiusY="2"/> <Rectangle x:Name="InnerBorder" Stroke="Transparent" StrokeThickness="1" RadiusX="2" RadiusY="2" Margin="1"/> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="MenuItemIconColumnGroup" MinWidth="24" Width="Auto"/> <ColumnDefinition Width="4"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="37"/> <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/> <ColumnDefinition Width="17"/> </Grid.ColumnDefinitions> <ContentPresenter x:Name="Icon" Margin="1" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Icon"/> <Border x:Name="GlyphPanel" Margin="1" Width="22" Height="22" Visibility="Hidden" Background="#E6EFF4" BorderBrush="#CDD3E6" BorderThickness="1" CornerRadius="3"> <Path x:Name="Glyph" Fill="#0C12A1" FlowDirection="LeftToRight" Width="9" Height="11" Data="{StaticResource Checkmark}"/> </Border> <ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="2" ContentSource="Header" RecognizesAccessKey="True"> <ContentPresenter.ContentTemplate> <DataTemplate> <AccessText Style="{StaticResource MenuAccessText}" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Header}" IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = IsEnabled}" Foreground="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MenuItem}}, Path = Foreground}"/> </DataTemplate> </ContentPresenter.ContentTemplate> </ContentPresenter> <TextBlock Margin="{TemplateBinding Padding}" Visibility="Collapsed" Grid.Column="4" Text="{TemplateBinding InputGestureText}"/> <Path Fill="{TemplateBinding Foreground}" Margin="4,0,0,0" VerticalAlignment="Center" Grid.Column="5" Data="{StaticResource RightArrow}"/> </Grid> <Popup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="-2" IsOpen="{Binding Path=IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Right" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-3" Focusable="false"> <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent"> <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}"> <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true"> <ItemsPresenter Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle"/> </ScrollViewer> </ContentControl> </Microsoft_Windows_Themes:SystemDropShadowChrome> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsSuspendingPopupAnimation" Value="true"> <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/> </Trigger> <Trigger Property="IsHighlighted" Value="true"> <Setter Property="Stroke" TargetName="InnerBorder" Value="#D1DBF4FF"/> </Trigger> <Trigger Property="Icon" Value="{x:Null}"> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="IsChecked" Value="true"> <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/> <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/> </Trigger> <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"> <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/> <Setter Property="Color" TargetName="Shdw" Value="#71000000"/> </Trigger> <Trigger Property="IsHighlighted" Value="true"> <Setter Property="Fill" TargetName="Bg" Value="{StaticResource MenuItemSelectionFill}"/> <Setter Property="Stroke" TargetName="Bg" Value="#8571CBF1"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="#FF9A9A9A"/> <Setter Property="Background" TargetName="GlyphPanel" Value="#EEE9E9"/> <Setter Property="BorderBrush" TargetName="GlyphPanel" Value="#DBD6D6"/> <Setter Property="Fill" TargetName="Glyph" Value="#848589"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style TargetType="{x:Type MenuItem}"> <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> <Style.Triggers> <Trigger Property="Role" Value="TopLevelHeader"> <Setter Property="Padding" Value="7,2,8,3"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> </Trigger> <Trigger Property="Role" Value="TopLevelItem"> <Setter Property="Padding" Value="7,2,8,3"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> </Trigger> <Trigger Property="Role" Value="SubmenuHeader"> <Setter Property="Padding" Value="2,3,2,3"/> <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}"/> </Trigger> <Trigger Property="Role" Value="SubmenuItem"> <Setter Property="Padding" Value="2,3,2,3"/> </Trigger> </Style.Triggers> </Style>

    • Edited by Max Palmer Tuesday, June 30, 2009 11:15 AM
    Tuesday, June 30, 2009 11:12 AM
  • Ok, seems to be a problem interpreting the Xaml comments, but hopefully that's clear!
    Tuesday, June 30, 2009 11:16 AM