Files
ShrlAlgoToolkit/Melskin/Controls/Menu.xaml

611 lines
33 KiB
Plaintext
Raw Normal View History

2025-07-31 20:12:01 +08:00
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2026-01-02 17:30:41 +08:00
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"
2026-01-02 17:30:30 +08:00
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
2025-07-31 20:12:01 +08:00
<!-- 菜单栏样式 -->
2025-07-11 09:20:23 +08:00
<Style TargetType="{x:Type Menu}">
2025-07-31 20:12:01 +08:00
<Setter Property="Background" Value="Transparent" />
2025-08-12 23:08:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
2025-07-31 20:12:01 +08:00
<Setter Property="VerticalContentAlignment" Value="Center" />
2025-07-11 09:20:23 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Menu}">
2025-07-31 20:12:01 +08:00
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-01-02 17:30:30 +08:00
Padding="{TemplateBinding Padding}"
2025-07-31 20:12:01 +08:00
SnapsToDevicePixels="true">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2025-07-11 09:20:23 +08:00
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-08-24 13:49:55 +08:00
<!--<SolidColorBrush Color="#0A000000" x:Key="MenuItem.Highlight.Disabled.Background" />
<SolidColorBrush Color="#21000000" x:Key="MenuItem.Highlight.Disabled.Border" />-->
2025-07-31 20:12:01 +08:00
<MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
2025-07-11 09:20:23 +08:00
2025-07-31 20:12:01 +08:00
<Style
BasedOn="{x:Null}"
2026-01-02 17:30:30 +08:00
TargetType="{x:Type RepeatButton}"
x:Key="MenuScrollButtonStyle">
2025-07-31 20:12:01 +08:00
<Setter Property="ClickMode" Value="Hover" />
2025-07-11 09:20:23 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
2025-07-31 20:12:01 +08:00
<Border
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="1"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="true"
x:Name="templateRoot">
<!--<ContentPresenter
Margin="6"
2025-07-31 20:12:01 +08:00
HorizontalAlignment="Center"
VerticalAlignment="Center" />-->
<ContentPresenter
2025-12-23 21:35:54 +08:00
Content="{Binding Path=(assists:ControlAssist.Icon), RelativeSource={RelativeSource TemplatedParent}}"
2026-01-02 17:30:30 +08:00
Margin="6"
TextElement.Foreground="{DynamicResource TextSecondaryBrush}"
x:Name="Icon" />
2025-07-11 09:20:23 +08:00
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-07-31 20:12:01 +08:00
<Style
BasedOn="{x:Null}"
2026-01-02 17:30:30 +08:00
TargetType="{x:Type ScrollViewer}"
x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer,
TypeInTargetAssembly={x:Type FrameworkElement}}">
2025-07-31 20:12:01 +08:00
<Setter Property="HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />
2025-07-11 09:20:23 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ScrollViewer}">
<Grid SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="*" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
2025-07-31 20:12:01 +08:00
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
2025-07-11 09:20:23 +08:00
</Grid.RowDefinitions>
2026-01-02 17:30:30 +08:00
<Border Grid.Column="0" Grid.Row="1">
<ScrollContentPresenter CanContentScroll="{TemplateBinding CanContentScroll}" Margin="{TemplateBinding Padding}" />
2025-07-11 09:20:23 +08:00
</Border>
2025-07-31 20:12:01 +08:00
<RepeatButton
Command="{x:Static ScrollBar.LineUpCommand}"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Focusable="false"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
Grid.Row="0"
Style="{StaticResource MenuScrollButtonStyle}"
assists:ControlAssist.Icon="{markup:Icon SymbolValue=ArrowDropUp}">
2025-07-11 09:20:23 +08:00
<RepeatButton.Visibility>
2025-07-31 20:12:01 +08:00
<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}" />
2025-07-11 09:20:23 +08:00
</MultiBinding>
</RepeatButton.Visibility>
</RepeatButton>
2025-07-31 20:12:01 +08:00
<RepeatButton
Command="{x:Static ScrollBar.LineDownCommand}"
CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
Focusable="false"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
Grid.Row="2"
Style="{StaticResource MenuScrollButtonStyle}"
assists:ControlAssist.Icon="{markup:Icon SymbolValue=ArrowDropDown}">
2025-07-11 09:20:23 +08:00
<RepeatButton.Visibility>
2025-07-31 20:12:01 +08:00
<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}" />
2025-07-11 09:20:23 +08:00
</MultiBinding>
</RepeatButton.Visibility>
</RepeatButton>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-07-31 20:12:01 +08:00
<!-- 顶层菜单 -->
2026-01-02 17:30:30 +08:00
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
2025-07-31 20:12:01 +08:00
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="true"
x:Name="templateRoot">
2025-07-11 09:20:23 +08:00
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Icon"
2025-07-31 20:12:01 +08:00
Height="16"
HorizontalAlignment="Center"
2026-01-02 17:30:30 +08:00
Margin="3"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
2025-07-31 20:12:01 +08:00
VerticalAlignment="Center"
2026-01-02 17:30:30 +08:00
Width="16"
x:Name="Icon" />
<controls:IconElement
FlowDirection="LeftToRight"
2025-12-23 21:35:54 +08:00
Foreground="{DynamicResource PrimaryGradientBrush}"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
Margin="2"
2025-12-23 21:35:54 +08:00
Symbol="Check"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Center"
Visibility="Collapsed"
x:Name="GlyphPanel" />
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Header"
2025-07-31 20:12:01 +08:00
Grid.Column="1"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center" />
2025-07-11 09:20:23 +08:00
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Icon" Value="{x:Null}">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsChecked" Value="true">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsEnabled" Value="False">
2026-01-02 17:30:30 +08:00
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Foreground" TargetName="GlyphPanel" Value="{DynamicResource PrimaryDisabledBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
2025-07-31 20:12:01 +08:00
<!-- TODO:调整此处样式 -->
2025-07-11 09:20:23 +08:00
<MultiTrigger>
<MultiTrigger.Conditions>
2025-07-31 20:12:01 +08:00
<Condition Property="IsHighlighted" Value="True" />
<Condition Property="IsEnabled" Value="False" />
2025-07-11 09:20:23 +08:00
</MultiTrigger.Conditions>
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource BorderNormalBrush}" />
2025-07-11 09:20:23 +08:00
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2025-07-31 20:12:01 +08:00
<!-- 顶层带子项的菜单 -->
2026-01-02 17:30:30 +08:00
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
2025-07-31 20:12:01 +08:00
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="true"
x:Name="templateRoot">
2025-07-11 09:20:23 +08:00
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Icon"
2025-07-31 20:12:01 +08:00
Height="16"
HorizontalAlignment="Center"
2025-07-31 20:12:01 +08:00
Margin="3"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
2025-07-31 20:12:01 +08:00
VerticalAlignment="Center"
2026-01-02 17:30:30 +08:00
Width="16"
x:Name="Icon" />
<controls:IconElement
FlowDirection="LeftToRight"
2025-12-23 21:35:54 +08:00
Foreground="{DynamicResource PrimaryGradientBrush}"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
Margin="3"
2025-12-23 21:35:54 +08:00
Symbol="Check"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Center"
Visibility="Collapsed"
x:Name="GlyphPanel" />
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Header"
2025-07-31 20:12:01 +08:00
Grid.Column="1"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<!-- 打开子菜单面板 -->
<Popup
AllowsTransparency="true"
Focusable="false"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
2025-07-31 20:12:01 +08:00
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=templateRoot}"
2026-01-02 17:30:30 +08:00
PopupAnimation="Fade"
x:Name="PART_Popup">
<decorations:LightedSurface
2025-08-12 23:08:54 +08:00
BorderBrush="{DynamicResource BorderGradientBrush}"
2025-07-31 20:12:01 +08:00
BorderThickness="1"
2026-01-02 17:30:30 +08:00
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">
2025-07-11 09:20:23 +08:00
<Grid RenderOptions.ClearTypeHint="Enabled">
2025-07-31 20:12:01 +08:00
<Canvas
Height="0"
HorizontalAlignment="Left"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Top"
Width="0">
2025-07-31 20:12:01 +08:00
<Rectangle
2026-01-02 17:30:30 +08:00
Fill="{Binding Background, ElementName=SubMenuBorder}"
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
2026-01-02 17:30:30 +08:00
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
x:Name="OpaqueRect" />
2025-07-11 09:20:23 +08:00
</Canvas>
2025-07-31 20:12:01 +08:00
<ItemsPresenter
Grid.IsSharedSizeScope="true"
KeyboardNavigation.DirectionalNavigation="Cycle"
KeyboardNavigation.TabNavigation="Cycle"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
2025-07-11 09:20:23 +08:00
</Grid>
</ScrollViewer>
</Border>
</decorations:LightedSurface>
2025-07-11 09:20:23 +08:00
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
2026-01-02 17:30:30 +08:00
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsChecked" Value="true">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource BackgroundFloatingBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsEnabled" Value="False">
2026-01-02 17:30:30 +08:00
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Foreground" TargetName="GlyphPanel" Value="{DynamicResource PrimaryDisabledBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
2026-01-02 17:30:30 +08:00
<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}" />
2025-07-11 09:20:23 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2025-07-31 20:12:01 +08:00
<!-- 弹出菜单 -->
2026-01-02 17:30:30 +08:00
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
2025-07-31 20:12:01 +08:00
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
2026-01-02 17:30:30 +08:00
Height="28"
Margin="0,1"
SnapsToDevicePixels="true"
x:Name="templateRoot">
2025-07-11 09:20:23 +08:00
<Grid Margin="-1">
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition
MinWidth="22"
2026-01-02 17:30:30 +08:00
SharedSizeGroup="MenuItemIconColumnGroup"
Width="Auto" />
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
2026-01-02 17:30:30 +08:00
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" />
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="12" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Icon"
2025-07-31 20:12:01 +08:00
Height="16"
HorizontalAlignment="Center"
2026-01-02 17:30:30 +08:00
Margin="3"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
2025-07-31 20:12:01 +08:00
VerticalAlignment="Center"
2026-01-02 17:30:30 +08:00
Width="16"
x:Name="Icon" />
2025-07-31 20:12:01 +08:00
<Border
2026-01-02 17:30:30 +08:00
Background="{DynamicResource ControlBackgroundSelectedBrush}"
ClipToBounds="False"
CornerRadius="4"
2025-07-31 20:12:24 +08:00
Grid.Column="0"
2025-07-31 20:12:01 +08:00
Height="22"
HorizontalAlignment="Center"
2026-01-02 17:30:30 +08:00
Margin="3"
2025-07-31 20:12:01 +08:00
VerticalAlignment="Center"
2026-01-02 17:30:30 +08:00
Visibility="Hidden"
Width="22"
x:Name="GlyphPanel">
<controls:IconElement
2025-12-23 21:35:54 +08:00
FlowDirection="LeftToRight"
Foreground="{DynamicResource PrimaryGradientBrush}"
2026-01-02 17:30:30 +08:00
HorizontalAlignment="Center"
Margin="4"
Symbol="Check"
VerticalAlignment="Center"
x:Name="Glyph" />
2025-07-11 09:20:23 +08:00
</Border>
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Header"
2025-07-31 20:12:01 +08:00
Grid.Column="1"
HorizontalAlignment="Left"
2026-01-02 17:30:30 +08:00
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center"
x:Name="menuHeaderContainer" />
2025-07-31 20:12:01 +08:00
<TextBlock
Grid.Column="3"
Margin="{TemplateBinding Padding}"
Opacity="0.7"
2026-01-02 17:30:30 +08:00
Text="{TemplateBinding InputGestureText}"
VerticalAlignment="Center"
x:Name="menuGestureText" />
2025-07-11 09:20:23 +08:00
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Icon" Value="{x:Null}">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsChecked" Value="True">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource BackgroundFloatingBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsEnabled" Value="False">
2026-01-02 17:30:30 +08:00
<Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Foreground" TargetName="Glyph" Value="{DynamicResource PrimaryDisabledBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
2025-07-31 20:12:01 +08:00
<!-- TODO:更改样式 -->
2025-07-11 09:20:23 +08:00
<MultiTrigger>
<MultiTrigger.Conditions>
2025-07-31 20:12:01 +08:00
<Condition Property="IsHighlighted" Value="True" />
<Condition Property="IsEnabled" Value="False" />
2025-07-11 09:20:23 +08:00
</MultiTrigger.Conditions>
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="templateRoot" Value="{DynamicResource BorderNormalBrush}" />
2025-07-11 09:20:23 +08:00
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2025-07-31 20:12:01 +08:00
<!-- 弹出带子项菜单 -->
2026-01-02 17:30:30 +08:00
<ControlTemplate TargetType="{x:Type MenuItem}" x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}">
2025-07-31 20:12:01 +08:00
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
2026-01-02 17:30:30 +08:00
Height="28"
Margin="0,1"
SnapsToDevicePixels="true"
x:Name="templateRoot">
2025-07-11 09:20:23 +08:00
<Grid Margin="-1">
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition
MinWidth="22"
2026-01-02 17:30:30 +08:00
SharedSizeGroup="MenuItemIconColumnGroup"
Width="Auto" />
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
2026-01-02 17:30:30 +08:00
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" />
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="12" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Icon"
2025-07-31 20:12:01 +08:00
Height="16"
HorizontalAlignment="Center"
2026-01-02 17:30:30 +08:00
Margin="3"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
2025-07-31 20:12:01 +08:00
VerticalAlignment="Center"
2026-01-02 17:30:30 +08:00
Width="16"
x:Name="Icon" />
2025-07-31 20:12:01 +08:00
<Border
2026-01-02 17:30:30 +08:00
Background="{DynamicResource ControlBackgroundSelectedBrush}"
CornerRadius="4"
2025-07-31 20:12:24 +08:00
Grid.Column="0"
2025-07-31 20:12:01 +08:00
Height="22"
HorizontalAlignment="Center"
2026-01-02 17:30:30 +08:00
Margin="3"
2025-07-31 20:12:01 +08:00
VerticalAlignment="Center"
2026-01-02 17:30:30 +08:00
Visibility="Hidden"
Width="22"
x:Name="GlyphPanel">
<controls:IconElement
2025-12-23 21:35:54 +08:00
FlowDirection="LeftToRight"
Foreground="{DynamicResource PrimaryGradientBrush}"
2026-01-02 17:30:30 +08:00
HorizontalAlignment="Center"
Margin="4"
Symbol="Check"
VerticalAlignment="Center"
x:Name="Glyph" />
2025-07-11 09:20:23 +08:00
</Border>
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-01-02 17:30:30 +08:00
ContentSource="Header"
2025-07-31 20:12:01 +08:00
Grid.Column="1"
HorizontalAlignment="Left"
2026-01-02 17:30:30 +08:00
Margin="{TemplateBinding Padding}"
2025-07-31 20:12:01 +08:00
RecognizesAccessKey="True"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center" />
2025-07-31 20:12:01 +08:00
<TextBlock
Grid.Column="3"
Margin="{TemplateBinding Padding}"
Opacity="0.7"
2026-01-02 17:30:30 +08:00
Text="{TemplateBinding InputGestureText}"
VerticalAlignment="Center" />
<controls:IconElement
Foreground="{DynamicResource TextPrimaryBrush}"
2026-01-02 17:30:30 +08:00
Grid.Column="4"
Symbol="KeyboardArrowRight"
x:Name="ArrowRight" />
2025-07-31 20:12:01 +08:00
<Popup
AllowsTransparency="true"
Focusable="false"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
2025-07-31 20:12:01 +08:00
HorizontalOffset="-2"
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Right"
PopupAnimation="Fade"
2026-01-02 17:30:30 +08:00
VerticalOffset="-3"
x:Name="PART_Popup">
<decorations:LightedSurface
2025-08-12 23:08:54 +08:00
BorderBrush="{DynamicResource BorderGradientBrush}"
2025-07-31 20:12:01 +08:00
BorderThickness="1"
2026-01-02 17:30:30 +08:00
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">
2025-07-11 09:20:23 +08:00
<Grid RenderOptions.ClearTypeHint="Enabled">
2025-07-31 20:12:01 +08:00
<Canvas
Height="0"
HorizontalAlignment="Left"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Top"
Width="0">
2025-07-31 20:12:01 +08:00
<Rectangle
2026-01-02 17:30:30 +08:00
Fill="{Binding Background, ElementName=SubMenuBorder}"
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
2026-01-02 17:30:30 +08:00
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
x:Name="OpaqueRect" />
2025-07-11 09:20:23 +08:00
</Canvas>
2025-07-31 20:12:01 +08:00
<ItemsPresenter
Grid.IsSharedSizeScope="true"
KeyboardNavigation.DirectionalNavigation="Cycle"
KeyboardNavigation.TabNavigation="Cycle"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
2025-07-11 09:20:23 +08:00
</Grid>
</ScrollViewer>
</Border>
</decorations:LightedSurface>
2025-07-11 09:20:23 +08:00
</Popup>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
2026-01-02 17:30:30 +08:00
<Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsChecked" Value="True">
2026-01-02 17:30:30 +08:00
<Setter Property="Visibility" TargetName="GlyphPanel" Value="Visible" />
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
2026-01-02 17:30:30 +08:00
<Setter Property="Background" TargetName="templateRoot" Value="{DynamicResource BackgroundFloatingBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="IsEnabled" Value="False">
2026-01-02 17:30:30 +08:00
<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}" />
2025-07-11 09:20:23 +08:00
</Trigger>
2026-01-02 17:30:30 +08:00
<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}" />
2025-07-11 09:20:23 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2025-07-31 20:12:01 +08:00
<!-- 菜单栏项目样式 -->
2025-07-11 09:20:23 +08:00
<Style TargetType="{x:Type MenuItem}">
2025-07-31 20:12:01 +08:00
<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}}}" />
2025-07-11 09:20:23 +08:00
<Style.Triggers>
2025-07-31 20:12:01 +08:00
<!-- 顶层带子项的菜单 -->
2025-07-11 09:20:23 +08:00
<Trigger Property="Role" Value="TopLevelHeader">
2025-07-31 20:12:01 +08:00
<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" />
2025-07-11 09:20:23 +08:00
</Trigger>
2025-07-31 20:12:01 +08:00
<!-- 顶层菜单 -->
2025-07-11 09:20:23 +08:00
<Trigger Property="Role" Value="TopLevelItem">
2025-08-12 23:08:54 +08:00
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
2025-07-31 20:12:01 +08:00
<Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
<Setter Property="Padding" Value="6,0" />
2025-07-11 09:20:23 +08:00
</Trigger>
2025-07-31 20:12:01 +08:00
<!-- 弹出带子项菜单 -->
2025-07-11 09:20:23 +08:00
<Trigger Property="Role" Value="SubmenuHeader">
2025-07-31 20:12:01 +08:00
<Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" />
2025-07-11 09:20:23 +08:00
</Trigger>
</Style.Triggers>
</Style>
2025-07-31 20:12:01 +08:00
<!-- 右键菜单样式 -->
2025-07-11 09:20:23 +08:00
<Style TargetType="{x:Type ContextMenu}">
2025-07-31 20:12:01 +08:00
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="2,0" />
2025-08-12 23:08:54 +08:00
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderGradientBrush}" />
2025-07-31 20:12:01 +08:00
<Setter Property="BorderThickness" Value="1" />
2025-07-11 09:20:23 +08:00
<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>
2025-07-31 20:12:01 +08:00
<Border
2025-07-11 09:20:23 +08:00
Background="{TemplateBinding Background}"
2025-07-31 20:12:01 +08:00
BorderThickness="0"
CornerRadius="4"
2026-01-02 17:30:30 +08:00
Effect="{DynamicResource PopupShadow}"
Margin="8"
Padding="0"
x:Name="Border">
2025-07-31 20:12:01 +08:00
<StackPanel
IsItemsHost="True"
2026-01-02 17:30:30 +08:00
KeyboardNavigation.DirectionalNavigation="Cycle"
Margin="2,1" />
2025-07-11 09:20:23 +08:00
</Border>
2025-07-31 20:12:01 +08:00
<Rectangle
Margin="8"
RadiusX="4"
RadiusY="4"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{TemplateBinding BorderThickness}" />
2025-07-11 09:20:23 +08:00
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>