Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Paste all this code into App.xaml (replace the existing ResourceDictionary though) -->
- <!-- 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 -->
- <!-- Menu already has a style and so does MenuItem, but the MenuItemTemplate styles the popups, aka the MI after the MI after the Menu -->
- <!-- Template="{DynamicResource MenuItemTemplate}" -->
- <!-- If you use many menu items within menuitems, when you get to the last menuitem thingy, use this (it removes the arrow) : -->
- <!-- Template="{DynamicResource FinalSubMenuItemTemplate}" -->
- <ResourceDictionary>
- <!--Menu style. automatically does stuff so no need to use template things. -->
- <Style TargetType="{x:Type Menu}">
- <Setter Property="Background" Value="#2d2d30"/>
- <Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
- <Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
- <Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
- <Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
- <Setter Property="Foreground" Value="#FFE6E6E6"/>
- <Setter Property="VerticalContentAlignment" Value="Center"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type Menu}">
- <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
- <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
- </Border>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <!--MenuItem style-->
- <Style TargetType="{x:Type MenuItem}">
- <Style.Triggers>
- <Trigger Property="MenuItem.Role" Value="TopLevelHeader">
- <Setter Property="Control.Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type MenuItem}">
- <Border x:Name="templateRoot" SnapsToDevicePixels="true"
- BorderThickness="{TemplateBinding BorderThickness}"
- Background="{TemplateBinding Background}"
- BorderBrush="{TemplateBinding BorderBrush}">
- <Grid VerticalAlignment="Center">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto"/>
- <ColumnDefinition Width="Auto"/>
- </Grid.ColumnDefinitions>
- <ContentPresenter x:Name="Icon" ContentSource="Icon"
- SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="Center"
- HorizontalAlignment="Center" Width="16" Height="16" Margin="3"/>
- <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"
- Visibility="Collapsed" VerticalAlignment="Center" Fill="{TemplateBinding Control.Foreground}"/>
- <ContentPresenter Grid.Column="1" ContentSource="Header" RecognizesAccessKey="true"
- Margin="{TemplateBinding Control.Padding}"
- SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
- <!-- The popup menu bit. This is where the good stuff is :)))) idk where the header goes but eh -->
- <Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="false"
- PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
- Placement="Bottom"
- IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
- PlacementTarget="{Binding ElementName=templateRoot}">
- <Border x:Name="SubMenuBorder" Background="#1b1b1c" BorderBrush="#333337"
- BorderThickness="1" Padding="2">
- <ScrollViewer x:Name="SubMenuScrollViewer"
- Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
- <Grid RenderOptions.ClearTypeHint="Enabled">
- <Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top">
- <Rectangle Name="OpaqueRect" Height="{Binding ElementName=SubMenuBorder, Path=ActualHeight}"
- Width="{Binding ElementName=SubMenuBorder, Path=ActualWidth}"
- Fill="{Binding ElementName=SubMenuBorder, Path=Background}"/>
- </Canvas>
- <!-- The little line between the icon and text. This is a nono-->
- <!--<Rectangle HorizontalAlignment="Left" Width="5" Margin="29,2,0,2" Fill="#FFD7D7D7"/>-->
- <ItemsPresenter x:Name="ItemsPresenter"
- KeyboardNavigation.DirectionalNavigation="Cycle"
- KeyboardNavigation.TabNavigation="Cycle" Grid.IsSharedSizeScope="true"
- SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"/>
- </Grid>
- </ScrollViewer>
- </Border>
- </Popup>
- <!-- The popup menu bit above. This is where the good stuff is :)))) -->
- </Grid>
- </Border>
- <ControlTemplate.Triggers>
- <Trigger Property="MenuItem.IsSuspendingPopupAnimation" Value="true">
- <Setter TargetName="PART_Popup" Property="Popup.PopupAnimation" Value="None"/>
- </Trigger>
- <Trigger Value="{x:Null}" Property="MenuItem.Icon">
- <Setter TargetName="Icon" Property="UIElement.Visibility" Value="Collapsed"/>
- </Trigger>
- <Trigger Property="MenuItem.IsChecked" Value="true">
- <Setter TargetName="GlyphPanel" Property="UIElement.Visibility" Value="Visible"/>
- <Setter TargetName="Icon" Property="UIElement.Visibility" Value="Collapsed"/>
- </Trigger>
- <!--Mouse Over basically-->
- <Trigger Property="MenuItem.IsHighlighted" Value="true">
- <Setter TargetName="templateRoot" Value="#3e3e40" Property="Background"/>
- <Setter TargetName="templateRoot" Value="#3e3e40" Property="BorderBrush"/>
- </Trigger>
- <Trigger Property="UIElement.IsEnabled" Value="false">
- <Setter TargetName="templateRoot" Value="#FF707070" Property="TextElement.Foreground"/>
- <Setter TargetName="GlyphPanel" Value="#FF707070" Property="Shape.Fill"/>
- </Trigger>
- <Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false">
- <Setter TargetName="OpaqueRect" Value="{Binding ElementName=SubMenuScrollViewer, Path=VerticalOffset}"
- Property="Canvas.Top"/>
- <Setter TargetName="OpaqueRect" Value="{Binding ElementName=SubMenuScrollViewer, Path=HorizontalOffset}"
- Property="Canvas.Left"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Trigger>
- </Style.Triggers>
- </Style>
- <ControlTemplate x:Key="MenuItemTemplate" TargetType="{x:Type MenuItem}">
- <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
- <Grid Margin="-1">
- <Grid.ColumnDefinitions>
- <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
- <ColumnDefinition Width="13"/>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="30"/>
- <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
- <ColumnDefinition Width="20"/>
- </Grid.ColumnDefinitions>
- <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
- <Border x:Name="GlyphPanel" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22">
- <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"/>
- </Border>
- <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"/>
- <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
- <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"/>
- <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">
- <Border x:Name="SubMenuBorder" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Padding="2">
- <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
- <Grid RenderOptions.ClearTypeHint="Enabled">
- <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
- <Rectangle x:Name="OpaqueRect"
- Fill="{Binding Background, ElementName=SubMenuBorder}"
- Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
- Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
- </Canvas>
- <!--<Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>-->
- <ItemsPresenter x:Name="ItemsPresenter"
- KeyboardNavigation.DirectionalNavigation="Cycle"
- Grid.IsSharedSizeScope="True"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
- KeyboardNavigation.TabNavigation="Cycle"/>
- </Grid>
- </ScrollViewer>
- </Border>
- </Popup>
- </Grid>
- </Border>
- <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="IsHighlighted" Value="True">
- <Setter TargetName="templateRoot" Value="#3e3e40" Property="Background"/>
- <Setter TargetName="templateRoot" Value="#3e3e40" Property="BorderBrush"/>
- </Trigger>
- <Trigger Property="IsEnabled" Value="False">
- <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
- <Setter Property="Fill" TargetName="Glyph" Value="#FF707070"/>
- <Setter Property="Fill" TargetName="RightArrow" Value="#FF707070"/>
- </Trigger>
- <Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
- <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
- <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- <ControlTemplate x:Key="FinalSubMenuItemTemplate" TargetType="{x:Type MenuItem}">
- <Border x:Name="templateRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
- <Grid Margin="-1">
- <Grid.ColumnDefinitions>
- <ColumnDefinition MinWidth="22" SharedSizeGroup="MenuItemIconColumnGroup" Width="Auto"/>
- <ColumnDefinition Width="13"/>
- <ColumnDefinition Width="*"/>
- <ColumnDefinition Width="30"/>
- <ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto"/>
- <ColumnDefinition Width="20"/>
- </Grid.ColumnDefinitions>
- <ContentPresenter x:Name="Icon" Content="{TemplateBinding Icon}" ContentSource="Icon" HorizontalAlignment="Center" Height="16" Margin="3" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center" Width="16"/>
- <Border x:Name="GlyphPanel" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Height="22" Margin="-1,0,0,0" Visibility="Hidden" VerticalAlignment="Center" Width="22">
- <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"/>
- </Border>
- <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"/>
- <TextBlock Grid.Column="4" Margin="{TemplateBinding Padding}" Opacity="0.7" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
- <Path x:Name="RightArrow" Fill="Transparent"/>
- <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">
- <Border x:Name="SubMenuBorder" Background="#1b1b1c" BorderBrush="#333337" BorderThickness="1" Padding="2">
- <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
- <Grid RenderOptions.ClearTypeHint="Enabled">
- <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
- <Rectangle x:Name="OpaqueRect"
- Fill="{Binding Background, ElementName=SubMenuBorder}"
- Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
- Width="{Binding ActualWidth, ElementName=SubMenuBorder}"/>
- </Canvas>
- <!--<Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" HorizontalAlignment="Left" Margin="29,2,0,2" Width="1"/>-->
- <ItemsPresenter x:Name="ItemsPresenter"
- KeyboardNavigation.DirectionalNavigation="Cycle"
- Grid.IsSharedSizeScope="True"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
- KeyboardNavigation.TabNavigation="Cycle"/>
- </Grid>
- </ScrollViewer>
- </Border>
- </Popup>
- </Grid>
- </Border>
- <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="IsHighlighted" Value="True">
- <Setter TargetName="templateRoot" Value="#3e3e40" Property="Background"/>
- <Setter TargetName="templateRoot" Value="#3e3e40" Property="BorderBrush"/>
- </Trigger>
- <Trigger Property="IsEnabled" Value="False">
- <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="#FF707070"/>
- <Setter Property="Fill" TargetName="Glyph" Value="#FF707070"/>
- <Setter Property="Fill" TargetName="RightArrow" Value="#FF707070"/>
- </Trigger>
- <Trigger Property="CanContentScroll" SourceName="SubMenuScrollViewer" Value="False">
- <Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}"/>
- <Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}"/>
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </ResourceDictionary>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement