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

368 lines
23 KiB
XML

<!-- TODO: Refactor editable and fix borders -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:WPFluent.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WPFluent;component/Resources/Variables.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="ComboBoxPadding">10,8,10,8</Thickness>
<Thickness x:Key="ComboBoxBorderThemeThickness">1,1,1,1</Thickness>
<Thickness x:Key="ComboBoxAccentBorderThemeThickness">0,0,0,2</Thickness>
<Thickness x:Key="ComboBoxChevronMargin">8,0,10,0</Thickness>
<Thickness x:Key="ComboBoxItemMargin">6,4,6,0</Thickness>
<Thickness x:Key="ComboBoxItemContentMargin">10,8,8,8</Thickness>
<system:Double x:Key="ComboBoxChevronSize">11.0</system:Double>
<system:Double x:Key="ComboBoxPopupMinHeight">32.0</system:Double>
<Style TargetType="{x:Type TextBox}" x:Key="DefaultComboBoxTextBoxStyle">
<!-- Focus by parent element -->
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<!-- Focus by parent element -->
<!-- Universal WPF UI ContextMenu -->
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<!-- Universal WPF UI ContextMenu -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="CaretBrush" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Cursor" Value="IBeam" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Margin" Value="0" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="0" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<controls:PassiveScrollViewer
HorizontalAlignment="Stretch"
Margin="{TemplateBinding Padding}"
Style="{DynamicResource DefaultTextBoxScrollViewerStyle}"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Stretch"
x:Name="PART_ContentHost" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Visibility" Value="Hidden" />
</Style>
<Style TargetType="{x:Type ToggleButton}" x:Key="DefaultComboBoxToggleButtonStyle">
<!-- Focus by parent element -->
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<!-- Focus by parent element -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="Border.CornerRadius" Value="0" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" 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}"
x:Name="ContentBorder">
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
x:Name="PART_ContentHost" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ComboBoxItem}" x:Key="DefaultComboBoxItemStyle">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="{StaticResource ComboBoxItemContentMargin}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Grid Background="Transparent">
<Border
CornerRadius="{TemplateBinding Border.CornerRadius}"
Margin="{DynamicResource ComboBoxItemMargin}"
Name="ContentBorder"
Padding="0"
SnapsToDevicePixels="True"
VerticalAlignment="Stretch">
<Grid>
<ContentPresenter
Margin="{TemplateBinding Padding}"
VerticalAlignment="Center"
x:Name="PART_ContentPresenter" />
<Rectangle
Fill="{DynamicResource SystemFillColorAttentionBrush}"
Height="16"
HorizontalAlignment="Left"
Margin="0"
RadiusX="2"
RadiusY="2"
VerticalAlignment="Center"
Visibility="Collapsed"
Width="3"
x:Name="ActiveRectangle" />
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="True">
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource SubtleFillColorSecondaryBrush}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="TextElement.Foreground" TargetName="PART_ContentPresenter" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Visibility" TargetName="ActiveRectangle" Value="Visible" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ComboBox}" x:Key="DefaultComboBoxStyle">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<!-- Universal WPF UI ContextMenu -->
<Setter Property="ContextMenu" Value="{DynamicResource DefaultControlContextMenu}" />
<!-- Universal WPF UI ContextMenu -->
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
<Setter Property="Border.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
<Setter Property="BorderBrush" Value="{DynamicResource ControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource ComboBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="{StaticResource TextControlThemeMinHeight}" />
<Setter Property="MinWidth" Value="{StaticResource TextControlThemeMinWidth}" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Padding" Value="{StaticResource ComboBoxPadding}" />
<Setter Property="Popup.Placement" Value="Bottom" />
<Setter Property="Popup.PopupAnimation" Value="None" />
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="VerticalAlignment" Value="Center" />
<!-- WPF doesn't like centering, the animation is ugly and the mouse button sometimes clicks right away. -->
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid>
<Border
BorderBrush="{DynamicResource SystemFillColorAttentionBrush}"
BorderThickness="{StaticResource ComboBoxAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Visibility="Collapsed"
x:Name="AccentBorder" />
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}"
Grid.Row="0"
HorizontalAlignment="Stretch"
MinHeight="{TemplateBinding MinHeight}"
MinWidth="{TemplateBinding MinWidth}"
VerticalAlignment="Stretch"
x:Name="ContentBorder">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Popup
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="{TemplateBinding Popup.Placement}"
PopupAnimation="{TemplateBinding Popup.PopupAnimation}"
VerticalAlignment="Center"
VerticalOffset="1"
x:Name="Popup">
<Border
Background="{DynamicResource AcrylicBackgroundFillColorDefaultBrush}"
BorderBrush="{DynamicResource SurfaceStrokeColorDefaultBrush}"
BorderThickness="1"
CornerRadius="{DynamicResource PopupCornerRadius}"
Margin="0"
MinWidth="{TemplateBinding ActualWidth}"
Padding="0,4,0,6"
SnapsToDevicePixels="True"
x:Name="DropDownBorder">
<Border.RenderTransform>
<TranslateTransform />
</Border.RenderTransform>
<Grid>
<controls:DynamicScrollViewer
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
Margin="0"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
SnapsToDevicePixels="True"
TextElement.FontSize="{TemplateBinding FontSize}"
TextElement.FontWeight="{TemplateBinding FontWeight}"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
<StackPanel
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Contained"
TextElement.FontSize="{TemplateBinding FontSize}" />
</controls:DynamicScrollViewer>
</Grid>
</Border>
</Popup>
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Grid.Column="0"
HorizontalAlignment="Stretch"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
Name="PART_ContentPresenter"
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Stretch" />
<ToggleButton
ClickMode="Press"
Focusable="False"
Foreground="{TemplateBinding Foreground}"
Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Name="ToggleButton"
Style="{StaticResource DefaultComboBoxToggleButtonStyle}"
VerticalAlignment="Stretch" />
<TextBox
FontSize="{TemplateBinding FontSize}"
Foreground="{TemplateBinding Foreground}"
Grid.Column="0"
HorizontalAlignment="Stretch"
IsReadOnly="{TemplateBinding IsReadOnly}"
Margin="{TemplateBinding Padding}"
Style="{StaticResource DefaultComboBoxTextBoxStyle}"
VerticalAlignment="Stretch"
x:Name="PART_EditableTextBox" />
<Grid Grid.Column="1" Margin="{StaticResource ComboBoxChevronMargin}">
<controls:SymbolIcon
FontSize="{StaticResource ComboBoxChevronSize}"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
IsHitTestVisible="False"
RenderTransformOrigin="0.5, 0.5"
Symbol="ChevronDown24"
VerticalAlignment="Center"
x:Name="ChevronIcon">
<controls:SymbolIcon.RenderTransform>
<RotateTransform Angle="0" />
</controls:SymbolIcon.RenderTransform>
</controls:SymbolIcon>
</Grid>
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsDropDownOpen" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="00:00:00.167"
From="0"
Storyboard.TargetName="ChevronIcon"
Storyboard.TargetProperty="(controls:SymbolIcon.RenderTransform).(RotateTransform.Angle)"
To="180" />
<DoubleAnimation
Duration="00:00:00.167"
From="-90"
Storyboard.TargetName="DropDownBorder"
Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
To="0">
<DoubleAnimation.EasingFunction>
<CircleEase EasingMode="EaseOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="00:00:00.167"
From="180"
Storyboard.TargetName="ChevronIcon"
Storyboard.TargetProperty="(controls:SymbolIcon.RenderTransform).(RotateTransform.Angle)"
To="0" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="MinHeight" TargetName="DropDownBorder" Value="{StaticResource ComboBoxPopupMinHeight}" />
</Trigger>
<Trigger Property="Popup.AllowsTransparency" SourceName="Popup" Value="False">
<Setter Property="CornerRadius" TargetName="DropDownBorder" Value="0" />
</Trigger>
<Trigger Property="IsGrouping" Value="True">
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</Trigger>
<Trigger Property="IsEditable" Value="True">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Visibility" TargetName="PART_EditableTextBox" Value="Visible" />
<Setter Property="Visibility" TargetName="PART_ContentPresenter" Value="Hidden" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True" />
<Condition Property="IsKeyboardFocusWithin" Value="True" />
<Condition Property="IsEditable" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorDefaultBrush}" />
<Setter Property="Visibility" TargetName="AccentBorder" Value="Visible" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="True" />
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsKeyboardFocusWithin" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorSecondaryBrush}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
<Style BasedOn="{StaticResource DefaultComboBoxItemStyle}" TargetType="{x:Type ComboBoxItem}" />
<Style BasedOn="{StaticResource DefaultComboBoxStyle}" TargetType="{x:Type ComboBox}" />
</ResourceDictionary>