Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: How to implement Blend's Dark theme for context menu

I have added this xaml in my App.xaml:

<Style TargetType="{x:Type ContextMenu}">
   <Setter Property="Background" Value="{StaticResource ShadeBrush}" />
   <Setter Property="BorderBrush" Value="{StaticResource ShadeBrush}" />
   <Setter Property="Foreground" Value="White" />
</Style>    

This gets me most of the way towards a dark theme....
How do I fix this problem with the menu items:
enter image description here

I suspect I need to modify the style or template for the menuitem.
Thanks.

UPDATE: Using Snoop (mentioned by Andy, thanks), I find this when selecting the white rect:
enter image description here

like image 305
Number8 Avatar asked Jan 14 '13 15:01

Number8


1 Answers

For whoever comes here next, I solved this problem by setting the template like so:

<Style TargetType="{x:Type ContextMenu}">
    <Setter Property="Background" Value="{StaticResource ShadeBrush}" />
    <Setter Property="BorderBrush" Value="{StaticResource ShadeBrush}" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ContextMenu}">
                <Border Uid="Border_93">
                    <Border.Style>
                        <Style TargetType="{x:Type Border}">
                            <Setter Property="Tag" 
                    Value="{DynamicResource 
                        {x:Static SystemParameters.DropShadowKey}}"/>
                            <Style.Triggers>
                                <DataTrigger 
                            Binding="{Binding Tag, 
                                RelativeSource={RelativeSource Self}}" 
                            Value="True">
                                    <Setter Property="Background" 
                            Value="Transparent"/>
                                    <Setter Property="Padding" 
                            Value="0,0,5,5"/>
                                    <Setter Property="Effect">
                                        <Setter.Value>
                                            <DropShadowEffect 
                                    BlurRadius="4" 
                                    Opacity="0.8" 
                                    ShadowDepth="1"/>
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Border.Style>
                    <Border BorderBrush="{TemplateBinding BorderBrush}" 
                BorderThickness="{TemplateBinding BorderThickness}" 
                Background="{TemplateBinding Background}" 
                Uid="Border_50">
                        <ScrollViewer CanContentScroll="True" 
                Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, 
                        TypeInTargetAssembly={x:Type FrameworkElement}}}" 
                        Uid="ScrollViewer_9">
                            <ItemsPresenter 
                    KeyboardNavigation.DirectionalNavigation="Cycle" 
                    Margin="{TemplateBinding Padding}" 
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                    Uid="ItemsPresenter_5"/>
                        </ScrollViewer>
                    </Border>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
like image 101
Menno Deij - van Rijswijk Avatar answered Nov 15 '22 08:11

Menno Deij - van Rijswijk