| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:sys="clr-namespace:System;assembly=mscorlib">
- <SolidColorBrush x:Key="MenuItem.MouseOver.Background">#E2E2E2</SolidColorBrush>
- <SolidColorBrush x:Key="MenuItem.MouseOver.Foreground">#000000</SolidColorBrush>
- <SolidColorBrush x:Key="ContextMenu.BorderBrush">#C4C4C4</SolidColorBrush>
- <!-- 设置阴影参数 -->
- <Thickness x:Key="ContextMenu.Shadow.Grid.Margin">12</Thickness>
- <sys:Double x:Key="ContextMenu.Shadow.BlurRadius">12</sys:Double>
- <Style x:Key="MaterialDesignMenu" TargetType="{x:Type MenuBase}">
- <Setter Property="Background" Value="#FFFFFF" />
- <Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
- <Setter Property="TextBlock.FontSize" Value="12" />
- <Setter Property="VerticalContentAlignment" Value="Center" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type MenuBase}">
- <Border Background="{TemplateBinding Background}"
- BorderBrush="{TemplateBinding BorderBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Padding="{TemplateBinding Padding}"
- SnapsToDevicePixels="true">
- <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
- </Border>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
- <Style BasedOn="{x:Null}" TargetType="{x:Type MenuItem}">
- <Setter Property="Padding" Value="20 0 20 0" />
- <Setter Property="OverridesDefaultStyle" Value="True" />
- <Setter Property="Background" Value="#FFFFFF" />
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type MenuItem}">
- <Grid ClipToBounds="True">
- <Border x:Name="templateRoot"
- Background="{TemplateBinding Background}"
- BorderBrush="{TemplateBinding BorderBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- SnapsToDevicePixels="True" />
- <Border x:Name="BackgroundRoot"
- Background="{TemplateBinding Background}"
- BorderBrush="{TemplateBinding BorderBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Opacity="0" SnapsToDevicePixels="True" />
- <Grid Height="{TemplateBinding Height}" Background="Transparent">
- <Grid Margin="{TemplateBinding Padding}"
- VerticalAlignment="Center" Background="Transparent">
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto" SharedSizeGroup="IconGroup" />
- <ColumnDefinition Width="*" SharedSizeGroup="HeaderGroup" />
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <Grid x:Name="IconWrapper" Width="40" Visibility="Visible">
- <ContentPresenter x:Name="Icon" Width="16" Height="10" HorizontalAlignment="Left"
- VerticalAlignment="Center"
- Content="{TemplateBinding Icon}"
- ContentSource="Icon"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
- </Grid>
- <Grid Grid.Column="1" Background="Transparent">
- <ContentPresenter x:Name="BoldHeaderPresenter" VerticalAlignment="Center"
- Content="{TemplateBinding Header}"
- ContentSource="Header"
- ContentStringFormat="{TemplateBinding HeaderStringFormat}"
- ContentTemplate="{TemplateBinding HeaderTemplate}"
- RecognizesAccessKey="True"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
- TextBlock.FontWeight="Normal" Visibility="Hidden" />
- <ContentPresenter x:Name="HeaderPresenter" VerticalAlignment="Center"
- Content="{TemplateBinding Header}"
- ContentSource="Header"
- ContentStringFormat="{TemplateBinding HeaderStringFormat}"
- ContentTemplate="{TemplateBinding HeaderTemplate}"
- RecognizesAccessKey="True"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
- </Grid>
- <Grid x:Name="SubBlock" Grid.Column="2" Margin="16 0 0 0" Visibility="Collapsed">
- <Path Width="5" Height="10" HorizontalAlignment="Right" VerticalAlignment="Center"
- Data="M0,0 5,5 0,10" SnapsToDevicePixels="False" Stretch="Uniform"
- Stroke="{TemplateBinding Foreground}"
- StrokeThickness="1" />
- </Grid>
- </Grid>
- </Grid>
- <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" HorizontalOffset="-2"
- IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
- Placement="Bottom" PopupAnimation="None">
- <Popup.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True" />
- </Popup.CacheMode>
- <Grid Margin="{StaticResource ContextMenu.Shadow.Grid.Margin}">
- <Border Background="#FFFFFF" CornerRadius="2" SnapsToDevicePixels="True" UseLayoutRounding="True">
- <Border.Effect>
- <DropShadowEffect BlurRadius="{StaticResource ContextMenu.Shadow.BlurRadius}"
- Opacity="0.2" ShadowDepth="0" Color="Brown" />
- </Border.Effect>
- </Border>
- <Border x:Name="SubMenuBorder" Margin="0"
- Background="{Binding Path=Background, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuBase}}"
- BorderBrush="{StaticResource ContextMenu.BorderBrush}"
- BorderThickness="1" CornerRadius="2"
- SnapsToDevicePixels="True"
- UseLayoutRounding="True">
- <Border Background="Transparent">
- <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
- <Grid Margin="0 1" RenderOptions.ClearTypeHint="Enabled">
- <Canvas Width="0" Height="0" HorizontalAlignment="Left" VerticalAlignment="Top">
- <Rectangle x:Name="OpaqueRect"
- Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
- Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
- Fill="{Binding Background, ElementName=SubMenuBorder}" />
- </Canvas>
- <ItemsPresenter x:Name="ItemsPresenter" Grid.IsSharedSizeScope="True"
- KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
- </Grid>
- </ScrollViewer>
- </Border>
- </Border>
- </Grid>
- </Popup>
- </Grid>
- <ControlTemplate.Triggers>
- <!--#region Roles Triggers-->
- <Trigger Property="Role" Value="SubmenuHeader">
- <Setter TargetName="SubBlock" Property="Visibility" Value="Visible" />
- <Setter TargetName="PART_Popup" Property="Placement" Value="Right" />
- <Setter Property="Height" Value="28" />
- <Setter Property="Foreground" Value="Black" />
- <Setter TargetName="BoldHeaderPresenter" Property="Visibility" Value="Collapsed" />
- </Trigger>
- <Trigger Property="Role" Value="SubmenuItem">
- <Setter Property="Height" Value="28" />
- <Setter Property="Foreground" Value="Black" />
- <Setter TargetName="BoldHeaderPresenter" Property="Visibility" Value="Collapsed" />
- </Trigger>
- <Trigger Property="Role" Value="TopLevelHeader">
- <Setter Property="Grid.IsSharedSizeScope" Value="True" />
- <Setter Property="Padding" Value="16 0" />
- <Setter Property="Height" Value="28" />
- <Setter TargetName="templateRoot" Property="CornerRadius" Value="2" />
- <Setter TargetName="BackgroundRoot" Property="CornerRadius" Value="2" />
- </Trigger>
- <Trigger Property="Role" Value="TopLevelItem">
- <Setter Property="Padding" Value="16 0" />
- <Setter Property="Height" Value="28" />
- <Setter TargetName="templateRoot" Property="CornerRadius" Value="2" />
- <Setter TargetName="BackgroundRoot" Property="CornerRadius" Value="2" />
- </Trigger>
- <MultiTrigger>
- <MultiTrigger.Conditions>
- <Condition Property="Role" Value="TopLevelHeader" />
- <Condition Property="IsSubmenuOpen" Value="True" />
- </MultiTrigger.Conditions>
- <MultiTrigger.Setters>
- <Setter TargetName="HeaderPresenter" Property="TextBlock.FontWeight" Value="Normal" />
- </MultiTrigger.Setters>
- </MultiTrigger>
- <!--#endregion-->
- <Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="True">
- <Setter TargetName="SubMenuBorder" Property="Margin" Value="0" />
- </Trigger>
- <Trigger Property="IsSuspendingPopupAnimation" Value="True">
- <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None" />
- </Trigger>
- <Trigger Property="Icon" Value="{x:Null}">
- <Setter TargetName="IconWrapper" Property="Visibility" Value="Collapsed" />
- </Trigger>
- <Trigger Property="IsCheckable" Value="True">
- <Setter TargetName="IconWrapper" Property="Visibility" Value="Collapsed" />
- </Trigger>
- <!--高亮状态-->
- <Trigger Property="IsHighlighted" Value="True">
- <Setter Property="Background" Value="{StaticResource MenuItem.MouseOver.Background}" />
- <Setter TargetName="BackgroundRoot" Property="Opacity" Value="0.13" />
- </Trigger>
- <Trigger Property="IsEnabled" Value="False">
- <Setter Property="Opacity" Value=".56" />
- </Trigger>
- <Trigger SourceName="SubMenuScrollViewer" Property="CanContentScroll" Value="False">
- <Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}" />
- <Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}" />
- </Trigger>
- <Trigger Property="IsMouseOver" Value="True">
- <Setter Property="Background" Value="{StaticResource MenuItem.MouseOver.Background}" />
- <Setter Property="Foreground" Value="{StaticResource MenuItem.MouseOver.Foreground}" />
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-
- <Style x:Key="DefaultContextMenuStyle" BasedOn="{StaticResource MaterialDesignMenu}" TargetType="{x:Type ContextMenu}">
- <Setter Property="Background" Value="Transparent" />
- <!--<Setter Property="ItemContainerStyle" Value="{StaticResource DefaultMenuItemStyle}" />-->
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type MenuBase}">
- <AdornerDecorator>
- <AdornerDecorator.CacheMode>
- <BitmapCache EnableClearType="True" SnapsToDevicePixels="True" />
- </AdornerDecorator.CacheMode>
- <Grid Margin="{StaticResource ContextMenu.Shadow.Grid.Margin}">
- <Border Background="#FFFFFF" CornerRadius="2" SnapsToDevicePixels="True" UseLayoutRounding="True">
- <Border.Effect>
- <DropShadowEffect BlurRadius="{StaticResource ContextMenu.Shadow.BlurRadius}"
- Opacity="0.2" ShadowDepth="0" Color="Brown" />
- </Border.Effect>
- </Border>
- <Border Margin="0"
- Background="{TemplateBinding Background}"
- BorderBrush="{StaticResource ContextMenu.BorderBrush}"
- BorderThickness="1" CornerRadius="2"
- SnapsToDevicePixels="True"
- UseLayoutRounding="True">
- <ScrollViewer x:Name="SubMenuScrollViewer" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}">
- <Grid Margin="0 2" RenderOptions.ClearTypeHint="Enabled">
- <ItemsPresenter x:Name="ItemsPresenter" Grid.IsSharedSizeScope="True"
- KeyboardNavigation.DirectionalNavigation="Cycle"
- KeyboardNavigation.TabNavigation="Cycle"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
- </Grid>
- </ScrollViewer>
- </Border>
- </Grid>
- </AdornerDecorator>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-
- </ResourceDictionary>
|