功能更新
This commit is contained in:
611
Melskin/Controls/Menu.xaml
Normal file
611
Melskin/Controls/Menu.xaml
Normal file
@@ -0,0 +1,611 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:assists="clr-namespace:Melskin.Assists"
|
||||
xmlns:controls="clr-namespace:Melskin.Controls"
|
||||
xmlns:decorations="clr-namespace:Melskin.Controls.Decorations"
|
||||
xmlns:markup="clr-namespace:Melskin.Markup"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<!-- 菜单栏样式 -->
|
||||
<Style TargetType="{x:Type Menu}">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type Menu}">
|
||||
<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>
|
||||
|
||||
<!--<SolidColorBrush Color="#0A000000" x:Key="MenuItem.Highlight.Disabled.Background" />
|
||||
<SolidColorBrush Color="#21000000" x:Key="MenuItem.Highlight.Disabled.Border" />-->
|
||||
<MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
|
||||
|
||||
<Style
|
||||
BasedOn="{x:Null}"
|
||||
TargetType="{x:Type RepeatButton}"
|
||||
x:Key="MenuScrollButtonStyle">
|
||||
<Setter Property="ClickMode" Value="Hover" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type RepeatButton}">
|
||||
<Border
|
||||
Background="Transparent"
|
||||
BorderBrush="Transparent"
|
||||
BorderThickness="1"
|
||||
SnapsToDevicePixels="true"
|
||||
x:Name="templateRoot">
|
||||
<!--<ContentPresenter
|
||||
Margin="6"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />-->
|
||||
<ContentPresenter
|
||||
Content="{Binding Path=(assists:ControlAssist.Icon), RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Margin="6"
|
||||
TextElement.Foreground="{DynamicResource TextSecondaryBrush}"
|
||||
x:Name="Icon" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style
|
||||
BasedOn="{x:Null}"
|
||||
TargetType="{x:Type ScrollViewer}"
|
||||
x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer,
|
||||
TypeInTargetAssembly={x:Type FrameworkElement}}">
|
||||
<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 CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}" />
|
||||
</Border>
|
||||
<RepeatButton
|
||||
Command="{x:Static ScrollBar.LineUpCommand}"
|
||||
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Focusable="false"
|
||||
Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Style="{StaticResource MenuScrollButtonStyle}"
|
||||
assists:ControlAssist.Icon="{markup:Icon SymbolValue=ArrowDropUp}">
|
||||
<RepeatButton.Visibility>
|
||||
<MultiBinding
|
||||
Converter="{StaticResource MenuScrollingVisibilityConverter}"
|
||||
ConverterParameter="0"
|
||||
FallbackValue="Visibility.Collapsed">
|
||||
<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>
|
||||
</RepeatButton>
|
||||
<RepeatButton
|
||||
Command="{x:Static ScrollBar.LineDownCommand}"
|
||||
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Focusable="false"
|
||||
Grid.Column="0"
|
||||
Grid.Row="2"
|
||||
Style="{StaticResource MenuScrollButtonStyle}"
|
||||
assists:ControlAssist.Icon="{markup:Icon SymbolValue=ArrowDropDown}">
|
||||
<RepeatButton.Visibility>
|
||||
<MultiBinding
|
||||
Converter="{StaticResource MenuScrollingVisibilityConverter}"
|
||||
ConverterParameter="100"
|
||||
FallbackValue="Visibility.Collapsed">
|
||||
<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>
|
||||
</RepeatButton>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- 顶层菜单 -->
|
||||
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
SnapsToDevicePixels="true"
|
||||
x:Name="templateRoot">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentPresenter
|
||||
ContentSource="Icon"
|
||||
Height="16"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="3"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center"
|
||||
Width="16"
|
||||
x:Name="Icon" />
|
||||
<controls:IconElement
|
||||
FlowDirection="LeftToRight"
|
||||
Foreground="{DynamicResource PrimaryGradientBrush}"
|
||||
Grid.Column="0"
|
||||
Margin="2"
|
||||
Symbol="Check"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Collapsed"
|
||||
x:Name="GlyphPanel" />
|
||||
<ContentPresenter
|
||||
ContentSource="Header"
|
||||
Grid.Column="1"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
RecognizesAccessKey="True"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<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="Background" TargetName="templateRoot" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Foreground" TargetName="GlyphPanel" Value="{DynamicResource PrimaryDisabledBrush}" />
|
||||
</Trigger>
|
||||
<!-- TODO:调整此处样式 -->
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsHighlighted" Value="True" />
|
||||
<Condition Property="IsEnabled" Value="False" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource BorderNormalBrush}" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<!-- 顶层带子项的菜单 -->
|
||||
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
SnapsToDevicePixels="true"
|
||||
x:Name="templateRoot">
|
||||
<Grid VerticalAlignment="Center">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentPresenter
|
||||
ContentSource="Icon"
|
||||
Height="16"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="3"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center"
|
||||
Width="16"
|
||||
x:Name="Icon" />
|
||||
<controls:IconElement
|
||||
FlowDirection="LeftToRight"
|
||||
Foreground="{DynamicResource PrimaryGradientBrush}"
|
||||
Grid.Column="0"
|
||||
Margin="3"
|
||||
Symbol="Check"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Collapsed"
|
||||
x:Name="GlyphPanel" />
|
||||
<ContentPresenter
|
||||
ContentSource="Header"
|
||||
Grid.Column="1"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
RecognizesAccessKey="True"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
|
||||
<!-- 打开子菜单面板 -->
|
||||
<Popup
|
||||
AllowsTransparency="true"
|
||||
Focusable="false"
|
||||
Grid.Column="0"
|
||||
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Placement="Bottom"
|
||||
PlacementTarget="{Binding ElementName=templateRoot}"
|
||||
PopupAnimation="Fade"
|
||||
x:Name="PART_Popup">
|
||||
<decorations:LightedSurface
|
||||
BorderBrush="{DynamicResource BorderGradientBrush}"
|
||||
BorderThickness="1"
|
||||
Effect="{DynamicResource PopupShadow}"
|
||||
Margin="8"
|
||||
Padding="0">
|
||||
<Border Margin="2,1" x:Name="SubMenuBorder">
|
||||
<ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" x:Name="SubMenuScrollViewer">
|
||||
<Grid RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas
|
||||
Height="0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Width="0">
|
||||
<Rectangle
|
||||
Fill="{Binding Background, ElementName=SubMenuBorder}"
|
||||
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
|
||||
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
|
||||
x:Name="OpaqueRect" />
|
||||
</Canvas>
|
||||
<ItemsPresenter
|
||||
Grid.IsSharedSizeScope="true"
|
||||
KeyboardNavigation.DirectionalNavigation="Cycle"
|
||||
KeyboardNavigation.TabNavigation="Cycle"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
x:Name="ItemsPresenter" />
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</decorations:LightedSurface>
|
||||
</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 Property="Background" TargetName="templateRoot" Value="{DynamicResource BackgroundFloatingBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Foreground" TargetName="GlyphPanel" Value="{DynamicResource PrimaryDisabledBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="ScrollViewer.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 TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
Height="28"
|
||||
Margin="0,1"
|
||||
SnapsToDevicePixels="true"
|
||||
x:Name="templateRoot">
|
||||
<Grid Margin="-1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition
|
||||
MinWidth="22"
|
||||
SharedSizeGroup="MenuItemIconColumnGroup"
|
||||
Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="30" />
|
||||
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" />
|
||||
<ColumnDefinition Width="12" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentPresenter
|
||||
ContentSource="Icon"
|
||||
Height="16"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="3"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center"
|
||||
Width="16"
|
||||
x:Name="Icon" />
|
||||
<Border
|
||||
Background="{DynamicResource ControlBackgroundSelectedBrush}"
|
||||
ClipToBounds="False"
|
||||
CornerRadius="4"
|
||||
Grid.Column="0"
|
||||
Height="22"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="3"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Hidden"
|
||||
Width="22"
|
||||
x:Name="GlyphPanel">
|
||||
<controls:IconElement
|
||||
FlowDirection="LeftToRight"
|
||||
Foreground="{DynamicResource PrimaryGradientBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="4"
|
||||
Symbol="Check"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="Glyph" />
|
||||
</Border>
|
||||
<ContentPresenter
|
||||
ContentSource="Header"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
RecognizesAccessKey="True"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="menuHeaderContainer" />
|
||||
<TextBlock
|
||||
Grid.Column="3"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
Opacity="0.7"
|
||||
Text="{TemplateBinding InputGestureText}"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="menuGestureText" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<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="Background" TargetName="templateRoot" Value="{DynamicResource BackgroundFloatingBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Foreground" TargetName="Glyph" Value="{DynamicResource PrimaryDisabledBrush}" />
|
||||
</Trigger>
|
||||
<!-- TODO:更改样式 -->
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsHighlighted" Value="True" />
|
||||
<Condition Property="IsEnabled" Value="False" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
|
||||
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource BorderNormalBrush}" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
<!-- 弹出带子项菜单 -->
|
||||
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
Height="28"
|
||||
Margin="0,1"
|
||||
SnapsToDevicePixels="true"
|
||||
x:Name="templateRoot">
|
||||
<Grid Margin="-1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition
|
||||
MinWidth="22"
|
||||
SharedSizeGroup="MenuItemIconColumnGroup"
|
||||
Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="30" />
|
||||
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" />
|
||||
<ColumnDefinition Width="12" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ContentPresenter
|
||||
ContentSource="Icon"
|
||||
Height="16"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="3"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center"
|
||||
Width="16"
|
||||
x:Name="Icon" />
|
||||
<Border
|
||||
Background="{DynamicResource ControlBackgroundSelectedBrush}"
|
||||
CornerRadius="4"
|
||||
Grid.Column="0"
|
||||
Height="22"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="3"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Hidden"
|
||||
Width="22"
|
||||
x:Name="GlyphPanel">
|
||||
<controls:IconElement
|
||||
FlowDirection="LeftToRight"
|
||||
Foreground="{DynamicResource PrimaryGradientBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="4"
|
||||
Symbol="Check"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="Glyph" />
|
||||
</Border>
|
||||
<ContentPresenter
|
||||
ContentSource="Header"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
RecognizesAccessKey="True"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="Center" />
|
||||
<TextBlock
|
||||
Grid.Column="3"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
Opacity="0.7"
|
||||
Text="{TemplateBinding InputGestureText}"
|
||||
VerticalAlignment="Center" />
|
||||
<controls:IconElement
|
||||
Foreground="{DynamicResource TextPrimaryBrush}"
|
||||
Grid.Column="4"
|
||||
Symbol="KeyboardArrowRight"
|
||||
x:Name="ArrowRight" />
|
||||
<Popup
|
||||
AllowsTransparency="true"
|
||||
Focusable="false"
|
||||
Grid.Column="0"
|
||||
HorizontalOffset="-2"
|
||||
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Placement="Right"
|
||||
PopupAnimation="Fade"
|
||||
VerticalOffset="-3"
|
||||
x:Name="PART_Popup">
|
||||
<decorations:LightedSurface
|
||||
BorderBrush="{DynamicResource BorderGradientBrush}"
|
||||
BorderThickness="1"
|
||||
Effect="{DynamicResource PopupShadow}"
|
||||
Margin="8"
|
||||
Padding="0">
|
||||
<Border Margin="2,1" x:Name="SubMenuBorder">
|
||||
<ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" x:Name="SubMenuScrollViewer">
|
||||
<Grid RenderOptions.ClearTypeHint="Enabled">
|
||||
<Canvas
|
||||
Height="0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Width="0">
|
||||
<Rectangle
|
||||
Fill="{Binding Background, ElementName=SubMenuBorder}"
|
||||
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
|
||||
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
|
||||
x:Name="OpaqueRect" />
|
||||
</Canvas>
|
||||
<ItemsPresenter
|
||||
Grid.IsSharedSizeScope="true"
|
||||
KeyboardNavigation.DirectionalNavigation="Cycle"
|
||||
KeyboardNavigation.TabNavigation="Cycle"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
x:Name="ItemsPresenter" />
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</decorations:LightedSurface>
|
||||
</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 Property="Background" TargetName="templateRoot" Value="{DynamicResource BackgroundFloatingBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Foreground" TargetName="Glyph" Value="{DynamicResource PrimaryDisabledBrush}" />
|
||||
<Setter Property="Foreground" TargetName="ArrowRight" Value="{DynamicResource TextDisabledBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="ScrollViewer.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>
|
||||
<!-- 菜单栏项目样式 -->
|
||||
<Style TargetType="{x:Type MenuItem}">
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="Padding" Value="2,0" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
|
||||
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
|
||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
|
||||
<!-- 默认弹出式菜单 -->
|
||||
<Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
|
||||
<Style.Triggers>
|
||||
<!-- 顶层带子项的菜单 -->
|
||||
<Trigger Property="Role" Value="TopLevelHeader">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
|
||||
<Setter Property="Padding" Value="6,0" />
|
||||
</Trigger>
|
||||
<!-- 顶层菜单 -->
|
||||
<Trigger Property="Role" Value="TopLevelItem">
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
|
||||
<Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
|
||||
<Setter Property="Padding" Value="6,0" />
|
||||
</Trigger>
|
||||
<!-- 弹出带子项菜单 -->
|
||||
<Trigger Property="Role" Value="SubmenuHeader">
|
||||
<Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<!-- 右键菜单样式 -->
|
||||
<Style TargetType="{x:Type ContextMenu}">
|
||||
<Setter Property="FontSize" Value="14" />
|
||||
<Setter Property="Padding" Value="2,0" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderGradientBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="Grid.IsSharedSizeScope" Value="true" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ContextMenu}">
|
||||
<Grid>
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderThickness="0"
|
||||
CornerRadius="4"
|
||||
Effect="{DynamicResource PopupShadow}"
|
||||
Margin="8"
|
||||
Padding="0"
|
||||
x:Name="Border">
|
||||
<StackPanel
|
||||
IsItemsHost="True"
|
||||
KeyboardNavigation.DirectionalNavigation="Cycle"
|
||||
Margin="2,1" />
|
||||
</Border>
|
||||
<Rectangle
|
||||
Margin="8"
|
||||
RadiusX="4"
|
||||
RadiusY="4"
|
||||
Stroke="{TemplateBinding BorderBrush}"
|
||||
StrokeThickness="{TemplateBinding BorderThickness}" />
|
||||
</Grid>
|
||||
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user