Files
ShrlAlgoToolkit/Melskin/Controls/ToolBar.xaml
2026-02-20 15:31:44 +08:00

268 lines
15 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Melskin.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="FlattenButton.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style
x:Key="{x:Static ToolBar.ButtonStyleKey}"
BasedOn="{StaticResource FlattenButtonStyle}"
TargetType="{x:Type Button}">
<Setter Property="Padding" Value="4,2" />
<Setter Property="Margin" Value="1,2" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
</Style>
<!-- 除展开按钮外的面板 -->
<Style x:Key="ToolBarMainPanelBorderStyle" TargetType="{x:Type Border}">
<Setter Property="Margin" Value="0,0,10,0" />
<Setter Property="CornerRadius" Value="4" />
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
<Setter Property="CornerRadius" Value="0" />
</DataTrigger>
</Style.Triggers>
</Style>
<!-- 前端拖拽指示 -->
<Style x:Key="ToolBarThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border
Padding="{TemplateBinding Padding}"
Background="Transparent"
SnapsToDevicePixels="True">
<Border Background="{DynamicResource BorderNormalBrush}" CornerRadius="1" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Cursor" Value="SizeAll" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 水平展开按钮 -->
<Style x:Key="ToolBarHorizontalOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="MinHeight" Value="0" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border
x:Name="Bd"
Width="10"
Background="{TemplateBinding Background}"
CornerRadius="0,4,4,0"
SnapsToDevicePixels="true">
<Grid Margin="1,2,3,1" VerticalAlignment="Bottom">
<Grid.RowDefinitions>
<RowDefinition Height="4" />
<RowDefinition Height="4" />
</Grid.RowDefinitions>
<Rectangle Height="1" Fill="{TemplateBinding Foreground}" />
<controls:IconElement
Grid.Row="1"
Foreground="{TemplateBinding Foreground}"
Symbol="ArrowDropDown" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource BackgroundFloatingBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</DataTrigger>
</Style.Triggers>
</Style>
<!-- 垂直展开按钮 -->
<Style x:Key="ToolBarVerticalOverflowButtonStyle" TargetType="{x:Type ToggleButton}">
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="MinHeight" Value="0" />
<Setter Property="MinWidth" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border
x:Name="Bd"
Background="{TemplateBinding Background}"
CornerRadius="0,0,4,4"
SnapsToDevicePixels="true">
<Grid
Width="4"
Margin="4"
HorizontalAlignment="Right">
<controls:IconElement
Grid.Column="1"
Foreground="{TemplateBinding Foreground}"
Symbol="ArrowRight" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource BackgroundFloatingBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ToolBar}">
<Setter Property="FontSize" Value="14" />
<Setter Property="Background" Value="{DynamicResource BackgroundLayoutBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextSecondaryBrush}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolBar}">
<Grid
x:Name="Grid"
Margin="4,2,2,2"
SnapsToDevicePixels="true">
<Grid x:Name="OverflowGrid" HorizontalAlignment="Right">
<!-- 展开按钮 -->
<ToggleButton
x:Name="OverflowButton"
ClickMode="Press"
FocusVisualStyle="{x:Null}"
IsChecked="{Binding IsOverflowOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
IsEnabled="{TemplateBinding HasOverflowItems}"
Style="{StaticResource ToolBarHorizontalOverflowButtonStyle}" />
<Popup
x:Name="OverflowPopup"
AllowsTransparency="true"
Focusable="false"
IsOpen="{Binding IsOverflowOpen, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Bottom"
PopupAnimation="None"
StaysOpen="false">
<Border
x:Name="ToolBarSubMenuBorder"
Margin="8"
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="0"
CornerRadius="4"
Effect="{DynamicResource PopupShadow}"
RenderOptions.ClearTypeHint="Enabled">
<ToolBarOverflowPanel
x:Name="PART_ToolBarOverflowPanel"
Margin="4,0"
FocusVisualStyle="{x:Null}"
Focusable="true"
KeyboardNavigation.DirectionalNavigation="Cycle"
KeyboardNavigation.TabNavigation="Cycle"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
WrapWidth="200" />
</Border>
</Popup>
</Grid>
<!-- 工具区域展开按钮除外 -->
<Border
x:Name="MainPanelBorder"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4,0,0,4"
Style="{StaticResource ToolBarMainPanelBorderStyle}">
<DockPanel KeyboardNavigation.TabIndex="1" KeyboardNavigation.TabNavigation="Local">
<Thumb
x:Name="ToolBarThumb"
Width="8"
Margin="0"
Padding="3"
Style="{StaticResource ToolBarThumbStyle}" />
<ContentPresenter
x:Name="ToolBarHeader"
Margin="4,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ContentSource="Header"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<!-- 菜单项目容器 -->
<ToolBarPanel
x:Name="PART_ToolBarPanel"
Margin="0"
IsItemsHost="true"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</DockPanel>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsOverflowOpen" Value="true">
<Setter TargetName="ToolBarThumb" Property="IsEnabled" Value="false" />
</Trigger>
<Trigger Property="Header" Value="{x:Null}">
<Setter TargetName="ToolBarHeader" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="ToolBarTray.IsLocked" Value="true">
<Setter TargetName="ToolBarThumb" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="Orientation" Value="Vertical">
<Setter TargetName="MainPanelBorder" Property="CornerRadius" Value="4,4,0,0" />
<Setter TargetName="Grid" Property="Margin" Value="2,4,2,2" />
<Setter TargetName="ToolBarThumb" Property="Height" Value="8" />
<Setter TargetName="ToolBarThumb" Property="Width" Value="Auto" />
<Setter TargetName="ToolBarThumb" Property="Padding" Value="3" />
<Setter TargetName="OverflowButton" Property="Style" Value="{StaticResource ToolBarVerticalOverflowButtonStyle}" />
<Setter TargetName="MainPanelBorder" Property="Margin" Value="0,0,0,10" />
<Setter TargetName="ToolBarHeader" Property="Margin" Value="0,4" />
<Setter TargetName="ToolBarThumb" Property="DockPanel.Dock" Value="Top" />
<Setter TargetName="ToolBarHeader" Property="DockPanel.Dock" Value="Top" />
<Setter TargetName="OverflowGrid" Property="HorizontalAlignment" Value="Stretch" />
<Setter TargetName="OverflowGrid" Property="VerticalAlignment" Value="Bottom" />
<Setter TargetName="OverflowPopup" Property="Placement" Value="Right" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type ToolBarTray}">
<Setter Property="Background" Value="Transparent" />
<Style.Triggers>
<DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="true">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>