Files
Shrlalgo.RvKits/WPFluent/Controls/SplitButton/SplitButton.xaml
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

175 lines
11 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:WPFluent.Controls"
xmlns:converters="clr-namespace:WPFluent.Converters"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Controls/Button/Button.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="ButtonChevronIconMargin">8,0,0,0</Thickness>
<converters:LeftSplitThicknessConverter x:Key="LeftSplitThicknessConverter" />
<converters:RightSplitThicknessConverter x:Key="RightSplitThicknessConverter" />
<converters:LeftSplitCornerRadiusConverter x:Key="LeftSplitCornerRadiusConverter" />
<converters:RightSplitCornerRadiusConverter x:Key="RightSplitCornerRadiusConverter" />
<Style TargetType="{x:Type ToggleButton}" x:Key="DefaultSplitButtonToggleButtonStyle">
<!-- Focus by parent element -->
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<!-- Focus by parent element -->
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Border.CornerRadius" Value="0" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}"
Margin="0,-1,-1,-1"
Padding="11,0"
x:Name="ContentBorder">
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
x:Name="PART_ContentHost" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style
BasedOn="{StaticResource DefaultUiButtonStyle}"
TargetType="{x:Type controls:SplitButton}"
x:Key="DefaultUiSplitButtonStyle">
<Setter Property="Popup.PopupAnimation" Value="None" />
<!-- WPF doesn't like centering, the animation is ugly and the mouse button sometimes clicks right away. -->
<Setter Property="Popup.Placement" Value="Bottom" />
<Setter Property="IsDropDownOpen" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:SplitButton}">
<Border
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}"
Height="{TemplateBinding Height}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
MinHeight="{TemplateBinding MinHeight}"
MinWidth="{TemplateBinding MinWidth}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Width="{TemplateBinding Width}"
x:Name="ContentBorder">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness,
Converter={StaticResource LeftSplitThicknessConverter}}"
CornerRadius="{TemplateBinding CornerRadius,
Converter={StaticResource LeftSplitCornerRadiusConverter}}"
Grid.Column="0"
Margin="0"
Padding="{TemplateBinding Padding}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentPresenter
Content="{TemplateBinding Icon}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Focusable="False"
Grid.Column="0"
Margin="{StaticResource ButtonIconMargin}"
TextElement.FontSize="{TemplateBinding FontSize}"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Center"
x:Name="ControlIcon" />
<ContentPresenter
Content="{TemplateBinding Content}"
Grid.Column="1"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Center"
x:Name="ContentPresenter" />
</Grid>
</Border>
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness,
Converter={StaticResource RightSplitThicknessConverter}}"
CornerRadius="{TemplateBinding CornerRadius,
Converter={StaticResource RightSplitCornerRadiusConverter}}"
Grid.Column="1"
Margin="0">
<ToggleButton
ClickMode="Press"
Focusable="False"
Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="Stretch"
IsChecked="{TemplateBinding IsDropDownOpen}"
Name="PART_ToggleButton"
Style="{StaticResource DefaultSplitButtonToggleButtonStyle}"
VerticalAlignment="Stretch">
<controls:SymbolIcon FontSize="10" Symbol="ChevronDown24" />
</ToggleButton>
</Border>
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsPressed" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="ContentBorder" Value="{Binding MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{Binding MouseOverBorderBrush, RelativeSource={RelativeSource TemplatedParent}}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsPressed" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="ContentBorder" Value="{Binding PressedBackground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{Binding PressedBorderBrush, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="TextElement.Foreground" TargetName="ContentPresenter" Value="{Binding PressedForeground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="TextElement.Foreground" TargetName="ControlIcon" Value="{Binding PressedForeground, RelativeSource={RelativeSource TemplatedParent}}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="TextElement.Foreground" TargetName="ContentPresenter" Value="{DynamicResource TextFillColorDisabledBrush}" />
</Trigger>
<Trigger Property="Content" Value="{x:Null}">
<Setter Property="Margin" TargetName="ControlIcon" Value="0" />
</Trigger>
<Trigger Property="Content" Value="">
<Setter Property="Margin" TargetName="ControlIcon" Value="0" />
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter Property="Margin" TargetName="ControlIcon" Value="0" />
<Setter Property="Visibility" TargetName="ControlIcon" Value="Collapsed" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource DefaultUiSplitButtonStyle}" TargetType="{x:Type controls:SplitButton}" />
</ResourceDictionary>