Files
Shrlalgo.RvKits/WPFluent/Controls/SplitButton/SplitButton.xaml

186 lines
11 KiB
XML

<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
All Rights Reserved.
Based on Microsoft XAML for Win UI
Copyright (c) Microsoft Corporation. All Rights Reserved.
-->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFluent.Controls"
xmlns:converters="clr-namespace:WPFluent.Converters">
<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 x:Key="DefaultSplitButtonToggleButtonStyle" TargetType="{x:Type ToggleButton}">
<!-- Focus by parent element -->
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<!-- Focus by parent element -->
<Setter Property="Foreground" Value="{DynamicResource ButtonForeground}" />
<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
x:Name="ContentBorder"
Margin="0,-1,-1,-1"
Padding="11,0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
<ContentPresenter
x:Name="PART_ContentHost"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style
x:Key="DefaultUiSplitButtonStyle"
BasedOn="{StaticResource DefaultUiButtonStyle}"
TargetType="{x:Type controls:SplitButton}">
<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
x:Name="ContentBorder"
Grid.Row="0"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border
Grid.Column="0"
Margin="0"
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness,
Converter={StaticResource LeftSplitThicknessConverter}}"
CornerRadius="{TemplateBinding CornerRadius,
Converter={StaticResource LeftSplitCornerRadiusConverter}}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentPresenter
x:Name="ControlIcon"
Grid.Column="0"
Margin="{StaticResource ButtonIconMargin}"
VerticalAlignment="Center"
Content="{TemplateBinding Icon}"
ContentTemplate="{TemplateBinding ContentTemplate}"
Focusable="False"
TextElement.FontSize="{TemplateBinding FontSize}"
TextElement.Foreground="{TemplateBinding Foreground}" />
<ContentPresenter
x:Name="ContentPresenter"
Grid.Column="1"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
TextElement.Foreground="{TemplateBinding Foreground}" />
</Grid>
</Border>
<Border
Grid.Column="1"
Margin="0"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness,
Converter={StaticResource RightSplitThicknessConverter}}"
CornerRadius="{TemplateBinding CornerRadius,
Converter={StaticResource RightSplitCornerRadiusConverter}}">
<ToggleButton
Name="PART_ToggleButton"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ClickMode="Press"
Focusable="False"
Foreground="{TemplateBinding Foreground}"
IsChecked="{TemplateBinding IsDropDownOpen}"
Style="{StaticResource DefaultSplitButtonToggleButtonStyle}">
<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 TargetName="ContentBorder" Property="Background" Value="{Binding MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{Binding MouseOverBorderBrush, RelativeSource={RelativeSource TemplatedParent}}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsPressed" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{Binding PressedBackground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{Binding PressedBorderBrush, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{Binding PressedForeground, RelativeSource={RelativeSource TemplatedParent}}" />
<Setter TargetName="ControlIcon" Property="TextElement.Foreground" Value="{Binding PressedForeground, RelativeSource={RelativeSource TemplatedParent}}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource ButtonBackgroundDisabled}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource ButtonBorderBrushDisabled}" />
<Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource ButtonForegroundDisabled}" />
</Trigger>
<Trigger Property="Content" Value="{x:Null}">
<Setter TargetName="ControlIcon" Property="Margin" Value="0" />
</Trigger>
<Trigger Property="Content" Value="">
<Setter TargetName="ControlIcon" Property="Margin" Value="0" />
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter TargetName="ControlIcon" Property="Margin" Value="0" />
<Setter TargetName="ControlIcon" Property="Visibility" Value="Collapsed" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style BasedOn="{StaticResource DefaultUiSplitButtonStyle}" TargetType="{x:Type controls:SplitButton}" />
</ResourceDictionary>