Files
ShrlAlgoToolkit/NeoUI/Melskin/Controls/ComboBox.xaml
2026-01-02 17:30:41 +08:00

950 lines
53 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:assists="clr-namespace:Melskin.Assists"
xmlns:controls="clr-namespace:Melskin.Controls"
xmlns:converters="clr-namespace:Melskin.Converters"
xmlns:decorations="clr-namespace:Melskin.Controls.Decorations"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="FlattenTextBox.xaml" />
<ResourceDictionary Source="/Melskin;component/Themes/Animations.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--#region 动画-->
<!-- 按钮高亮 -->
<Storyboard x:Key="Button.FocusEffect">
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetName="border"
Storyboard.TargetProperty="Intensity"
To="0.8" />
<BooleanAnimationUsingKeyFrames
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="ShaderEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
<!-- 按钮取消高亮 -->
<Storyboard x:Key="Button.LeaveEffect">
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetName="border"
Storyboard.TargetProperty="Intensity"
To="0" />
<BooleanAnimationUsingKeyFrames
Duration="0:0:0.2"
Storyboard.TargetName="border"
Storyboard.TargetProperty="ShaderEnabled">
<DiscreteBooleanKeyFrame KeyTime="0:0:0.2" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
<!-- 按钮按下 -->
<Storyboard x:Key="Button.PressEffect">
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="Intensity"
To="0.4" />
</Storyboard>
<!--#endregion-->
<!-- 内容样式 -->
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Padding" Value="12,4,8,4" />
<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="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Grid Margin="0,1">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="True"
x:Name="Bd">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<!-- 选中标记 -->
<Border
CornerRadius="4"
Visibility="Hidden"
x:Name="Indicator">
<Border
Background="{DynamicResource PrimaryNormalBrush}"
CornerRadius="2"
HorizontalAlignment="Left"
Margin="2,4"
Width="4" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Visibility" TargetName="Indicator" Value="Visible" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
<!--<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource PrimaryFocusedBrush}" />
</Trigger>-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--#region FloatStyle-->
<Style TargetType="{x:Type ToggleButton}" x:Key="FloatComboBoxToggleButton">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Focusable" Value="False" />
<Setter Property="ClickMode" Value="Press" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<decorations:EmbossBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Intensity="0"
ShaderEnabled="False"
SnapsToDevicePixels="True"
x:Name="border">
<!-- 下拉箭头 -->
<Border
BorderBrush="Transparent"
BorderThickness="1"
HorizontalAlignment="Right"
Margin="0"
SnapsToDevicePixels="True"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
x:Name="splitBorder">
<controls:IconElement
Foreground="{DynamicResource TextPrimaryBrush}"
RenderTransformOrigin="0.5,0.5"
SnapsToDevicePixels="false"
Symbol="KeyboardArrowDown"
x:Name="arrow">
<controls:IconElement.RenderTransform>
<RotateTransform Angle="0" />
</controls:IconElement.RenderTransform>
</controls:IconElement>
</Border>
</decorations:EmbossBorder>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource BorderGradientBrush}" />
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Button.FocusEffect}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource Button.LeaveEffect}" />
</Trigger.ExitActions>
</Trigger>
<!-- 缩减阴影,下压效果 -->
<Trigger Property="IsPressed" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Button.PressEffect}" x:Name="pressBegin" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="pressBegin" />
</Trigger.ExitActions>
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource BorderGradientBrush}" />
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandRotateStoryboard}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseRotateStoryboard}" />
</Trigger.ExitActions>
</Trigger>
<!-- 按钮禁用效果 -->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" TargetName="arrow" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 可编辑模板 -->
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="FloatComboBoxEditableTemplate">
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
</Grid.ColumnDefinitions>
<Popup
AllowsTransparency="True"
Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-8"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="4"
x:Name="PART_Popup">
<Border
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Margin="8"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
x:Name="dropDownBorder">
<ScrollViewer Margin="4,3" x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled" x:Name="grid">
<Canvas
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
<Rectangle
Fill="{Binding Background, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
x:Name="opaqueRect" />
</Canvas>
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
</Grid>
</ScrollViewer>
</Border>
</Popup>
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="0"
Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-4"
Style="{StaticResource FloatComboBoxToggleButton}"
x:Name="toggleButton" />
<!-- 输入框 -->
<TextBox
Background="Transparent"
Grid.Column="0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Style="{StaticResource FlattenTextBoxStyle}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="PART_EditableTextBox" />
<!-- 水印 -->
<TextBlock
Foreground="{DynamicResource TextPlaceholderBrush}"
Grid.Column="0"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
Padding="4"
Text="{Binding Path=(assists:InputAssist.PlaceholderText), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}"
VerticalAlignment="Center"
x:Name="Placeholder">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=ComboBox}}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
<!-- 后台给文本赋值时触发 -->
<DataTrigger Binding="{Binding Text, RelativeSource={RelativeSource AncestorType=ComboBox}, Converter={x:Static converters:NullOrEmptyConverter.Instance}}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
<ControlTemplate.Triggers>
<!--<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.56" />
</Trigger>-->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" TargetName="PART_EditableTextBox" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True" />
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="True" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</MultiTrigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="FloatComboBoxTemplate">
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
</Grid.ColumnDefinitions>
<Popup
AllowsTransparency="True"
Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-8"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="4"
x:Name="PART_Popup">
<Border
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Margin="8"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
x:Name="dropDownBorder">
<ScrollViewer Margin="4,3" x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled" x:Name="grid">
<Canvas
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
<Rectangle
Fill="{Binding Background, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
x:Name="opaqueRect" />
</Canvas>
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
</Grid>
</ScrollViewer>
</Border>
</Popup>
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="0"
Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource FloatComboBoxToggleButton}"
x:Name="toggleButton" />
<TextBlock
Foreground="{DynamicResource TextPlaceholderBrush}"
Grid.Column="0"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
Padding="3"
Text="{Binding Path=(assists:InputAssist.PlaceholderText), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}"
VerticalAlignment="Center"
x:Name="Placeholder">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=ComboBox}}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Grid.Column="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="True" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</MultiTrigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="{x:Type ComboBox}" x:Key="FloatComboBoxStyle">
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="assists:InputAssist.PlaceholderText" Value="请选择..." />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="8" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.CanContentScroll" Value="True" />
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="Template" Value="{StaticResource FloatComboBoxTemplate}" />
<Style.Triggers>
<Trigger Property="IsEditable" Value="True">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Padding" Value="3" />
<Setter Property="Template" Value="{StaticResource FloatComboBoxEditableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
<!--#endregion-->
<Style TargetType="{x:Type ToggleButton}" x:Key="ComboBoxToggleButton">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Focusable" Value="False" />
<Setter Property="ClickMode" Value="Press" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}"
SnapsToDevicePixels="True"
x:Name="border">
<!-- 下拉箭头 -->
<Border
BorderBrush="Transparent"
BorderThickness="1"
HorizontalAlignment="Right"
Margin="0"
SnapsToDevicePixels="True"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
x:Name="splitBorder">
<controls:IconElement
Foreground="{DynamicResource TextPrimaryBrush}"
RenderTransformOrigin="0.5,0.5"
SnapsToDevicePixels="false"
Symbol="KeyboardArrowDown"
x:Name="arrow">
<controls:IconElement.RenderTransform>
<RotateTransform Angle="0" />
</controls:IconElement.RenderTransform>
</controls:IconElement>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryFocusedBrush}" />
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandRotateStoryboard}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseRotateStoryboard}" />
</Trigger.ExitActions>
</Trigger>
<!-- 按钮禁用效果 -->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" TargetName="arrow" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 可编辑模板 -->
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="ComboBoxEditableTemplate">
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
</Grid.ColumnDefinitions>
<Popup
AllowsTransparency="True"
Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-8"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="4"
x:Name="PART_Popup">
<Border
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Margin="8"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
x:Name="dropDownBorder">
<ScrollViewer Margin="4,3" x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled" x:Name="grid">
<Canvas
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
<Rectangle
Fill="{Binding Background, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
x:Name="opaqueRect" />
</Canvas>
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
</Grid>
</ScrollViewer>
</Border>
</Popup>
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="0"
Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ComboBoxToggleButton}"
x:Name="toggleButton" />
<!-- 输入框 -->
<TextBox
Background="Transparent"
Grid.Column="0"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Style="{StaticResource FlattenTextBoxStyle}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="PART_EditableTextBox" />
<!-- 水印 -->
<Grid
Grid.Column="0"
IsHitTestVisible="False"
Margin="{TemplateBinding BorderThickness}">
<!-- 使用 Border 来模拟 Padding这样可以更精确控制内部 TextBlock 的位置 -->
<Border BorderThickness="0" Padding="{TemplateBinding Padding}">
<TextBlock
Foreground="{DynamicResource TextPlaceholderBrush}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="2,0,0,0"
Text="{Binding Path=(assists:InputAssist.PlaceholderText), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="Placeholder">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=ComboBox}}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
<!-- 后台给文本赋值时触发 -->
<DataTrigger Binding="{Binding Text, RelativeSource={RelativeSource AncestorType=ComboBox}, Converter={x:Static converters:NullOrEmptyConverter.Instance}}" Value="False">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Border>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" TargetName="PART_EditableTextBox" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True" />
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="True" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</MultiTrigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- 默认控件模板 -->
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="ComboBoxTemplate">
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
</Grid.ColumnDefinitions>
<Popup
AllowsTransparency="True"
Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="4"
x:Name="PART_Popup">
<Border
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Margin="8"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
x:Name="dropDownBorder">
<ScrollViewer Margin="4,3" x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled" x:Name="grid">
<Canvas
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
<Rectangle
Fill="{Binding Background, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
x:Name="opaqueRect" />
</Canvas>
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
</Grid>
</ScrollViewer>
</Border>
</Popup>
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="0"
Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ComboBoxToggleButton}"
x:Name="toggleButton" />
<!-- 占位符 TextBlock (保持原样,它已经有了 Margin) -->
<TextBlock
Foreground="{DynamicResource TextPlaceholderBrush}"
Grid.Column="0"
IsHitTestVisible="False"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Text="{Binding Path=(assists:InputAssist.PlaceholderText), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}"
VerticalAlignment="Center"
x:Name="Placeholder">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=ComboBox}}" Value="{x:Null}">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<!-- 核心修改:在 ContentPresenter 外层增加一个 Border 来模拟 BorderThickness -->
<Border
BorderBrush="Transparent"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="0">
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="True" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</MultiTrigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- 默认ComboBox样式 -->
<Style TargetType="{x:Type ComboBox}" x:Key="DefaultComboBoxStyle">
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="assists:InputAssist.PlaceholderText" Value="请选择..." />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Padding" Value="10,8" />
<Setter Property="FontSize" Value="14" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.CanContentScroll" Value="True" />
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="Template" Value="{StaticResource ComboBoxTemplate}" />
<Style.Triggers>
<Trigger Property="IsEditable" Value="True">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
<!-- 默认下拉样式 -->
<Style BasedOn="{StaticResource DefaultComboBoxStyle}" TargetType="{x:Type ComboBox}" />
<!--#region 工具栏样式-->
<!-- 工具栏下拉Toggle -->
<Style TargetType="{x:Type ToggleButton}" x:Key="ToolbarComboBoxToggleButtonStyle">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Focusable" Value="False" />
<Setter Property="ClickMode" Value="Press" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
Margin="4"
SnapsToDevicePixels="True"
x:Name="border">
<!-- 下拉箭头 -->
<Border
BorderBrush="Transparent"
BorderThickness="1"
HorizontalAlignment="Right"
Margin="0"
Padding="0,0,2,0"
SnapsToDevicePixels="True"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
x:Name="splitBorder">
<controls:IconElement
Foreground="{DynamicResource TextPrimaryBrush}"
RenderTransformOrigin="0.5,0.5"
SnapsToDevicePixels="false"
Symbol="KeyboardArrowDown"
x:Name="arrow">
<controls:IconElement.RenderTransform>
<RotateTransform Angle="0" />
</controls:IconElement.RenderTransform>
</controls:IconElement>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryNormalBrush}" />
</Trigger>
<!-- 下压效果 -->
<Trigger Property="IsPressed" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryPressedBrush}" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryFocusedBrush}" />
<Setter Property="RenderTransform" TargetName="arrow">
<Setter.Value>
<RotateTransform Angle="180" />
</Setter.Value>
</Setter>
</Trigger>
<!-- 按钮禁用效果 -->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" TargetName="arrow" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 工具栏默认样式 -->
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="ToolBarComboBoxTemplate">
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
</Grid.ColumnDefinitions>
<Popup
AllowsTransparency="True"
Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-8"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="4"
x:Name="PART_Popup">
<Border
Background="{DynamicResource BackgroundFloatingBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Margin="8"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
x:Name="dropDownBorder">
<ScrollViewer Margin="4,3" x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled" x:Name="grid">
<Canvas
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
<Rectangle
Fill="{Binding Background, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
x:Name="opaqueRect" />
</Canvas>
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
</Grid>
</ScrollViewer>
</Border>
</Popup>
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Grid.Column="0"
Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-4"
Style="{StaticResource ToolbarComboBoxToggleButtonStyle}"
x:Name="toggleButton" />
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Grid.Column="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
</Trigger>
<Trigger Property="HasItems" Value="False">
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="True" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
</MultiTrigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="False">
<Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- 工具栏下拉样式 -->
<Style
BasedOn="{StaticResource DefaultComboBoxStyle}"
TargetType="{x:Type ComboBox}"
x:Key="{x:Static ToolBar.ComboBoxStyleKey}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="4,2" />
<Setter Property="Template" Value="{StaticResource ToolBarComboBoxTemplate}" />
</Style>
<!--#endregion-->
</ResourceDictionary>