Advertisement
bobmarley12345

MenuItemDarkTheme

Nov 10th, 2019
1,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 22.84 KB | None | 0 0
  1. <!-- Paste all this code into App.xaml (replace the existing ResourceDictionary though) -->
  2.  
  3. <!--  for using it, dont put the below code in the Menu, or the Menuitem after the menu, but the menuitem after the menuitem after the menu -->
  4. <!--  Menu already has a style and so does MenuItem, but the MenuItemTemplate styles the popups, aka the MI after the MI after the Menu -->
  5. <!--  Template="{DynamicResource MenuItemTemplate}"  -->
  6.            
  7. <!--  If you use many menu items within menuitems, when you get to the last menuitem thingy, use this (it removes the arrow) : -->
  8. <!--  Template="{DynamicResource FinalSubMenuItemTemplate}"  -->
  9.  
  10. <ResourceDictionary>
  11.             <!--Menu style. automatically does stuff so no need to use template things. -->
  12.             <Style TargetType="{x:Type Menu}">
  13.                 <Setter Property="Background" Value="#2d2d30"/>
  14.                 <Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
  15.                 <Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
  16.                 <Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
  17.                 <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
  18.                 <Setter Property="Foreground" Value="#FFE6E6E6"/>
  19.                 <Setter Property="VerticalContentAlignment" Value="Center"/>
  20.                 <Setter Property="Template">
  21.                     <Setter.Value>
  22.                         <ControlTemplate TargetType="{x:Type Menu}">
  23.                             <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
  24.                                 <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  25.                             </Border>
  26.                         </ControlTemplate>
  27.                     </Setter.Value>
  28.                 </Setter>
  29.             </Style>
  30.            
  31.             <!--MenuItem style-->
  32.             <Style TargetType="{x:Type MenuItem}">
  33.                 <Style.Triggers>
  34.                     <Trigger Property="MenuItem.Role" Value="TopLevelHeader">
  35.                         <Setter Property="Control.Template">
  36.                             <Setter.Value>
  37.                                 <ControlTemplate TargetType="{x:Type MenuItem}">
  38.                                     <Border x:Name="templateRoot" SnapsToDevicePixels="true"
  39.                                        BorderThickness="{TemplateBinding BorderThickness}"
  40.                                        Background="{TemplateBinding Background}"
  41.                                        BorderBrush="{TemplateBinding BorderBrush}">
  42.                                         <Grid VerticalAlignment="Center">
  43.                                             <Grid.ColumnDefinitions>
  44.                                                 <ColumnDefinition Width="Auto"/>
  45.                                                 <ColumnDefinition Width="Auto"/>
  46.                                             </Grid.ColumnDefinitions>
  47.                                             <ContentPresenter x:Name="Icon" ContentSource="Icon"
  48.                                                          SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="Center"
  49.                                                          HorizontalAlignment="Center" Width="16" Height="16" Margin="3"/>
  50.                                             <Path x:Name="GlyphPanel" Data="F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z" FlowDirection="LeftToRight" Margin="3"
  51.                                              Visibility="Collapsed" VerticalAlignment="Center" Fill="{TemplateBinding Control.Foreground}"/>
  52.                                             <ContentPresenter Grid.Column="1" ContentSource="Header" RecognizesAccessKey="true"
  53.                                                          Margin="{TemplateBinding Control.Padding}"
  54.                                                          SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
  55.  
  56.                                             <!-- The popup menu bit. This is where the good stuff is :)))) idk where the header goes but eh -->
  57.                                             <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false"
  58.                                                   PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
  59.                                                   Placement="Bottom"
  60.                                                   IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
  61.                                                   PlacementTarget="{Binding ElementName=templateRoot}">
  62.  
  63.                                                 <Border x:Name="SubMenuBorder" Background="#1b1b1c" BorderBrush="#333337"
  64.                                                    BorderThickness="1" Padding="2">
  65.                                                     <ScrollViewer x:Name="SubMenuScrollViewer"
  66.                                                             Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
  67.                                                         <Grid RenderOptions.ClearTypeHint="Enabled">
  68.                                                             <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
  69.                                                                 <Rectangle Name="OpaqueRect" Height="{Binding ElementName=SubMenuBorder, Path=ActualHeight}"
  70.                                                                           Width="{Binding ElementName=SubMenuBorder, Path=ActualWidth}"
  71.                                                                           Fill="{Binding ElementName=SubMenuBorder, Path=Background}"/>
  72.                                                             </Canvas>
  73.                                                             <!-- The little line between the icon and text. This is a nono-->
  74.                                                             <!--<Rectangle HorizontalAlignment="Left" Width="5" Margin="29,2,0,2" Fill="#FFD7D7D7"/>-->
  75.                                                             <ItemsPresenter x:Name="ItemsPresenter"
  76.                                                                            KeyboardNavigation.DirectionalNavigation="Cycle"
  77.                                                                            KeyboardNavigation.TabNavigation="Cycle" Grid.IsSharedSizeScope="true"
  78.                                                                            SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
  79.                                                         </Grid>
  80.                                                     </ScrollViewer>
  81.                                                 </Border>
  82.                                             </Popup>
  83.                                             <!-- The popup menu bit above. This is where the good stuff is :)))) -->
  84.  
  85.                                         </Grid>
  86.                                     </Border>
  87.                                     <ControlTemplate.Triggers>
  88.                                         <Trigger Property="MenuItem.IsSuspendingPopupAnimation" Value="true">
  89.                                             <Setter TargetName="PART_Popup" Property="Popup.PopupAnimation" Value="None"/>
  90.                                         </Trigger>
  91.                                         <Trigger Value="{x:Null}" Property="MenuItem.Icon">
  92.                                             <Setter TargetName="Icon" Property="UIElement.Visibility" Value="Collapsed"/>
  93.                                         </Trigger>
  94.                                         <Trigger Property="MenuItem.IsChecked" Value="true">
  95.                                             <Setter TargetName="GlyphPanel" Property="UIElement.Visibility" Value="Visible"/>
  96.                                             <Setter TargetName="Icon" Property="UIElement.Visibility" Value="Collapsed"/>
  97.                                         </Trigger>
  98.                                         <!--Mouse Over basically-->
  99.                                         <Trigger Property="MenuItem.IsHighlighted" Value="true">
  100.                                             <Setter TargetName="templateRoot" Value="#3e3e40" Property="Background"/>
  101.                                             <Setter TargetName="templateRoot" Value="#3e3e40" Property="BorderBrush"/>
  102.                                         </Trigger>
  103.                                         <Trigger Property="UIElement.IsEnabled" Value="false">
  104.                                             <Setter TargetName="templateRoot" Value="#FF707070" Property="TextElement.Foreground"/>
  105.                                             <Setter TargetName="GlyphPanel" Value="#FF707070" Property="Shape.Fill"/>
  106.                                         </Trigger>
  107.                                         <Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false">
  108.                                             <Setter TargetName="OpaqueRect" Value="{Binding ElementName=SubMenuScrollViewer, Path=VerticalOffset}"
  109.                                                Property="Canvas.Top"/>
  110.                                             <Setter TargetName="OpaqueRect" Value="{Binding ElementName=SubMenuScrollViewer, Path=HorizontalOffset}"
  111.                                                Property="Canvas.Left"/>
  112.                                         </Trigger>
  113.                                     </ControlTemplate.Triggers>
  114.                                 </ControlTemplate>
  115.                             </Setter.Value>
  116.                         </Setter>
  117.                     </Trigger>
  118.                 </Style.Triggers>
  119.             </Style>
  120.            
  121.             <ControlTemplate x:Key="MenuItemTemplate" TargetType="{x:Type MenuItem}">
  122.                 <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
  123.                     <Grid Margin="-1">
  124.                         <Grid.ColumnDefinitions>
  125.                             <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
  126.                             <ColumnDefinition Width="13"/>
  127.                             <ColumnDefinition Width="*"/>
  128.                             <ColumnDefinition Width="30"/>
  129.                             <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
  130.                             <ColumnDefinition Width="20"/>
  131.                         </Grid.ColumnDefinitions>
  132.                         <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
  133.                         <Border x:Name="GlyphPanel" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22">
  134.                             <Path x:Name="Glyph" Data="F1M10,1.2L4.7,9.1 4.5,9.1 0,5.2 1.3,3.5 4.3,6.1 8.3,0 10,1.2z" Fill="#FF212121" FlowDirection="LeftToRight" Height="11" Width="9"/>
  135.                         </Border>
  136.                         <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="2" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
  137.                         <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
  138.                         <Path x:Name="RightArrow" Grid.Column="5" Data="M0,0L4,3.5 0,7z" Fill="#FF212121" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center"/>
  139.                         <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" HorizontalOffset="-2" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3">
  140.                             <Border x:Name="SubMenuBorder" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Padding="2">
  141.                                 <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
  142.                                     <Grid RenderOptions.ClearTypeHint="Enabled">
  143.                                         <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
  144.                                             <Rectangle x:Name="OpaqueRect"
  145.                                                       Fill="{Binding Background, ElementName=SubMenuBorder}"
  146.                                                       Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
  147.                                                       Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
  148.                                         </Canvas>
  149.                                         <!--<Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>-->
  150.                                         <ItemsPresenter x:Name="ItemsPresenter"
  151.                                                        KeyboardNavigation.DirectionalNavigation="Cycle"
  152.                                                        Grid.IsSharedSizeScope="True"
  153.                                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  154.                                                        KeyboardNavigation.TabNavigation="Cycle"/>
  155.                                     </Grid>
  156.                                 </ScrollViewer>
  157.                             </Border>
  158.                         </Popup>
  159.                     </Grid>
  160.                 </Border>
  161.                 <ControlTemplate.Triggers>
  162.                     <Trigger Property="IsSuspendingPopupAnimation" Value="True">
  163.                         <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
  164.                     </Trigger>
  165.                     <Trigger Property="Icon" Value="{x:Null}">
  166.                         <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
  167.                     </Trigger>
  168.                     <Trigger Property="IsChecked" Value="True">
  169.                         <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
  170.                         <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
  171.                     </Trigger>
  172.                     <Trigger Property="IsHighlighted" Value="True">
  173.                         <Setter TargetName="templateRoot" Value="#3e3e40" Property="Background"/>
  174.                         <Setter TargetName="templateRoot" Value="#3e3e40" Property="BorderBrush"/>
  175.                     </Trigger>
  176.                     <Trigger Property="IsEnabled" Value="False">
  177.                         <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
  178.                         <Setter Property="Fill" TargetName="Glyph" Value="#FF707070"/>
  179.                         <Setter Property="Fill" TargetName="RightArrow" Value="#FF707070"/>
  180.                     </Trigger>
  181.                     <Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
  182.                         <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
  183.                         <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
  184.                     </Trigger>
  185.                 </ControlTemplate.Triggers>
  186.             </ControlTemplate>
  187.  
  188.             <ControlTemplate x:Key="FinalSubMenuItemTemplate" TargetType="{x:Type MenuItem}">
  189.                 <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
  190.                     <Grid Margin="-1">
  191.                         <Grid.ColumnDefinitions>
  192.                             <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
  193.                             <ColumnDefinition Width="13"/>
  194.                             <ColumnDefinition Width="*"/>
  195.                             <ColumnDefinition Width="30"/>
  196.                             <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
  197.                             <ColumnDefinition Width="20"/>
  198.                         </Grid.ColumnDefinitions>
  199.                         <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
  200.                         <Border x:Name="GlyphPanel" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22">
  201.                             <Path x:Name="Glyph" Data="F1M10,1.2L4.7,9.1 4.5,9.1 0,5.2 1.3,3.5 4.3,6.1 8.3,0 10,1.2z" Fill="#FF212121" FlowDirection="LeftToRight" Height="11" Width="9"/>
  202.                         </Border>
  203.                         <ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="2" ContentStringFormat="{TemplateBinding HeaderStringFormat}" ContentSource="Header" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
  204.                         <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
  205.                         <Path x:Name="RightArrow" Fill="Transparent"/>
  206.                         <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" HorizontalOffset="-2" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Right" VerticalOffset="-3">
  207.                             <Border x:Name="SubMenuBorder" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Padding="2">
  208.                                 <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
  209.                                     <Grid RenderOptions.ClearTypeHint="Enabled">
  210.                                         <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
  211.                                             <Rectangle x:Name="OpaqueRect"
  212.                                                       Fill="{Binding Background, ElementName=SubMenuBorder}"
  213.                                                       Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
  214.                                                       Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
  215.                                         </Canvas>
  216.                                         <!--<Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>-->
  217.                                         <ItemsPresenter x:Name="ItemsPresenter"
  218.                                                        KeyboardNavigation.DirectionalNavigation="Cycle"
  219.                                                        Grid.IsSharedSizeScope="True"
  220.                                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  221.                                                        KeyboardNavigation.TabNavigation="Cycle"/>
  222.                                     </Grid>
  223.                                 </ScrollViewer>
  224.                             </Border>
  225.                         </Popup>
  226.                     </Grid>
  227.                 </Border>
  228.                 <ControlTemplate.Triggers>
  229.                     <Trigger Property="IsSuspendingPopupAnimation" Value="True">
  230.                         <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
  231.                     </Trigger>
  232.                     <Trigger Property="Icon" Value="{x:Null}">
  233.                         <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
  234.                     </Trigger>
  235.                     <Trigger Property="IsChecked" Value="True">
  236.                         <Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible"/>
  237.                         <Setter Property="Visibility" TargetName="Icon" Value="Collapsed"/>
  238.                     </Trigger>
  239.                     <Trigger Property="IsHighlighted" Value="True">
  240.                         <Setter TargetName="templateRoot" Value="#3e3e40" Property="Background"/>
  241.                         <Setter TargetName="templateRoot" Value="#3e3e40" Property="BorderBrush"/>
  242.                     </Trigger>
  243.                     <Trigger Property="IsEnabled" Value="False">
  244.                         <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
  245.                         <Setter Property="Fill" TargetName="Glyph" Value="#FF707070"/>
  246.                         <Setter Property="Fill" TargetName="RightArrow" Value="#FF707070"/>
  247.                     </Trigger>
  248.                     <Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
  249.                         <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
  250.                         <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
  251.                     </Trigger>
  252.                 </ControlTemplate.Triggers>
  253.             </ControlTemplate>
  254.         </ResourceDictionary>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement