Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Controls/NeuComboBox.xaml

377 lines
25 KiB
Plaintext
Raw Normal View History

2025-08-20 12:10:13 +08:00
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2025-08-20 12:10:35 +08:00
xmlns:assists="clr-namespace:NeoUI.Assists"
xmlns:controls="clr-namespace:NeoUI.Controls"
xmlns:conv="clr-namespace:NeoUI.Converters"
2025-08-20 12:10:13 +08:00
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
2025-08-20 12:10:35 +08:00
<ResourceDictionary Source="/NeoUI;component/Controls/ComboBoxStyle.xaml" />
2025-08-20 12:10:13 +08:00
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type ListBoxItem}" x:Key="NeuComboBoxItemStyle">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Padding" Value="8,6" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true"
x:Name="Bd">
<Grid>
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" />
2025-08-20 12:10:35 +08:00
<controls:IconElement
2025-08-20 12:10:13 +08:00
FontWeight="Bold"
Foreground="{DynamicResource PrimaryNormalBrush}"
HorizontalAlignment="Right"
Symbol="Check"
VerticalAlignment="Center"
Visibility="Collapsed"
x:Name="CheckMark" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
<Setter Property="Visibility" TargetName="CheckMark" Value="Visible" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-08-20 12:10:35 +08:00
<Style TargetType="{x:Type controls:NeuComboBox}">
2025-08-20 12:10:13 +08:00
<!--<Setter Property="Background" Value="{DynamicResource BackgroundContainerBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />-->
<Setter Property="BorderThickness" Value="1" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="4" />
<Setter Property="Padding" Value="10,8" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="assists:InputAssist.Clearable" Value="True" />
<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">
<Setter.Value>
2025-08-20 12:10:35 +08:00
<ControlTemplate TargetType="{x:Type controls:NeuComboBox}">
2025-08-20 12:10:13 +08:00
<Grid>
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
Margin="-4"
Style="{DynamicResource ComboBoxToggleButton}"
x:Name="ToggleButton">
<!--<ToggleButton.Template>
<ControlTemplate TargetType="ToggleButton">
<Border
Background="{Binding Background, RelativeSource={RelativeSource AncestorType=local:NeuComboBox}}"
BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=local:NeuComboBox}}"
BorderThickness="{Binding BorderThickness, RelativeSource={RelativeSource AncestorType=local:NeuComboBox}}"
CornerRadius="2"
x:Name="Border" />
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
2025-08-20 12:10:35 +08:00
<Setter Property="BorderBrush" TargetName="Border" Value="{DynamicResource AdditionalBlueColor}" />
2025-08-20 12:10:13 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>-->
</ToggleButton>
2025-08-20 12:10:35 +08:00
<!-- TODO 待处理因为箭头是否需要旋转的原因暂时保留templateRoot -->
2025-08-20 12:10:13 +08:00
<Grid x:Name="templateRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
2025-08-20 12:10:35 +08:00
<Grid ClipToBounds="True" Grid.Column="0">
2025-08-20 12:10:13 +08:00
<Grid VerticalAlignment="Center">
<!-- 占位符 水印 -->
<TextBlock
Foreground="{DynamicResource TextSecondaryBrush}"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
2025-08-20 12:10:35 +08:00
Text="{Binding PlaceHolder, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}}"
2025-08-20 12:10:13 +08:00
VerticalAlignment="Center"
x:Name="PlaceholderTextBlock">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<!-- 多选:无标签 -->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
2025-08-20 12:10:35 +08:00
<Condition Binding="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}}" Value="{x:Static SelectionMode.Multiple}" />
2025-08-20 12:10:13 +08:00
<Condition Binding="{Binding HasItems, ElementName=TagItemsControl}" Value="False" />
<!--<Condition Binding="{Binding SelectedItems.Count, RelativeSource={RelativeSource AncestorType=local:NeuComboBox}, TargetNullValue=0}" Value="0" />-->
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger>
<!-- 单选:未选 -->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
2025-08-20 12:10:35 +08:00
<Condition Binding="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}}" Value="{x:Static SelectionMode.Single}" />
<Condition Binding="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}}" Value="{x:Null}" />
2025-08-20 12:10:13 +08:00
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<!-- 多选 Tag 列表 -->
<!--<ItemsControl x:Name="TagItemsControl" ItemsSource="{Binding SelectedItems, Mode=OneWay, RelativeSource={RelativeSource AncestorType=local:NeuComboBox}}">-->
<ItemsControl ItemsSource="{Binding ElementName=PART_ListBox, Path=SelectedItems}" x:Name="TagItemsControl">
<ItemsControl.Style>
<Style TargetType="ItemsControl">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
2025-08-20 12:10:35 +08:00
<DataTrigger Binding="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}}" Value="{x:Static SelectionMode.Multiple}">
2025-08-20 12:10:13 +08:00
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
<!-- 标签滚动但是有bug 影响选择 -->
<!--<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>-->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
2025-08-20 12:10:35 +08:00
<controls:Tag
2025-08-20 12:10:13 +08:00
Closable="True"
Content="{Binding}"
Margin="2,2,4,2" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ContentPresenter
2025-08-20 12:10:35 +08:00
Content="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}}"
2025-08-20 12:10:13 +08:00
ContentStringFormat="{Binding DisplayMemberPath, RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="False"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
2025-08-20 12:10:35 +08:00
Visibility="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:NeuComboBox}, Converter={x:Static conv:ComparisionToVisibilityConverter.Instance}, ConverterParameter={x:Static SelectionMode.Single}}" />
2025-08-20 12:10:13 +08:00
</Grid>
</Grid>
<!-- 下拉箭头 -->
2025-08-20 12:10:35 +08:00
<!--<local:IconElement
2025-08-20 12:10:13 +08:00
x:Name="Arrow"
Grid.Column="1"
Margin="0,0,8,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="{DynamicResource TextSecondaryBrush}"
RenderTransformOrigin="0.5,0.5"
Symbol="KeyboardArrowUp">
2025-08-20 12:10:35 +08:00
<local:IconElement.RenderTransform>
2025-08-20 12:10:13 +08:00
<RotateTransform x:Name="ArrowRotateTransform" CenterX="0.5" CenterY="0.5" />
2025-08-20 12:10:35 +08:00
</local:IconElement.RenderTransform>
</local:IconElement>-->
2025-08-20 12:10:13 +08:00
<!--#region 无用代码-->
<!--<Path
x:Name="Arrow"
Grid.Column="1"
Margin="0,0,8,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="M 0 0 L 4 4 L 8 0 Z"
Fill="#444">
<Path.RenderTransform>
-->
<!-- 将旋转中心设置在箭头的几何中心 (宽8高4中心是x=4, y=2) -->
<!--
<RotateTransform x:Name="ArrowRotateTransform" CenterX="4" CenterY="2" />
</Path.RenderTransform>
</Path>-->
<!--<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="templateRoot"
Storyboard.TargetProperty="Opacity"
To="0.65" />
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="templateRoot"
Storyboard.TargetProperty="Opacity"
To="1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled" />
</VisualStateGroup>
<VisualStateGroup x:Name="CheckStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Checked">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Arrow"
Storyboard.TargetProperty="RenderTransform.Angle"
To="180" />
</Storyboard>
</VisualState>
<VisualState x:Name="Unchecked">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Arrow"
Storyboard.TargetProperty="RenderTransform.Angle"
To="0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>-->
<!--#endregion-->
</Grid>
<Popup
AllowsTransparency="True"
Focusable="False"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-8"
MinWidth="{Binding ActualWidth, ElementName=ToggleButton}"
Placement="Bottom"
PopupAnimation="Slide"
StaysOpen="False"
VerticalOffset="4"
x:Name="dropDownBorder">
<Border
Background="{DynamicResource BackgroundLayoutBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Effect="{DynamicResource PopupShadow}"
Margin="8"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<!-- 用于 TextBox -->
<RowDefinition Height="*" />
<!-- 用于 ListBox占据剩余空间 -->
</Grid.RowDefinitions>
<TextBox
Grid.Row="0"
Margin="6,6,6,2"
Padding="4,2"
Text="{Binding FilterText, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Top"
Visibility="{Binding IsFilteringEnabled, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static conv:BooleanToVisibilityConverter.CollapsedInstance}}"
assists:InputAssist.Clearable="{TemplateBinding assists:InputAssist.Clearable}"
x:Name="PART_FilterTextBox">
<assists:InputAssist.Suffix>
<Path
Data="M 6.332031 2 C 8.726562 2 10.667969 3.941406 10.667969 6.332031 C 10.667969 7.40625 10.273438 8.394531 9.625 9.152344 L 9.808594 9.332031 L 10.332031 9.332031 L 13.667969 12.667969 L 12.667969 13.667969 L 9.332031 10.332031 L 9.332031 9.808594 L 9.152344 9.625 C 8.394531 10.273438 7.40625 10.667969 6.332031 10.667969 C 3.941406 10.667969 2 8.726562 2 6.332031 C 2 3.941406 3.941406 2 6.332031 2 M 6.332031 3.332031 C 4.667969 3.332031 3.332031 4.667969 3.332031 6.332031 C 3.332031 8 4.667969 9.332031 6.332031 9.332031 C 8 9.332031 9.332031 8 9.332031 6.332031 C 9.332031 4.667969 8 3.332031 6.332031 3.332031 Z M 6.332031 3.332031 "
DockPanel.Dock="Left"
Fill="{DynamicResource TextSecondaryBrush}"
Height="16"
Margin="4,2,2,0"
VerticalAlignment="Center"
Width="16" />
</assists:InputAssist.Suffix>
</TextBox>
<ListBox
BorderThickness="0"
DisplayMemberPath="{Binding DisplayMemberPath, RelativeSource={RelativeSource TemplatedParent}}"
Grid.Row="1"
ItemContainerStyle="{StaticResource NeuComboBoxItemStyle}"
ItemsSource="{Binding FilteredItems, RelativeSource={RelativeSource TemplatedParent}}"
SelectionMode="{Binding SelectionMode, RelativeSource={RelativeSource TemplatedParent}}"
x:Name="PART_ListBox" />
</Grid>
</Border>
</Popup>
</Grid>
<!-- 下拉箭头旋转动画 -->
<!--<ControlTemplate.Triggers>
-->
<!-- 这个触发器会在 IsDropDownOpen 属性变为 True 时激活 -->
<!--
<Trigger Property="IsDropDownOpen" Value="True">
<Trigger.EnterActions>
-->
<!-- 进入时(下拉框打开),开始一个动画故事板 -->
<!--
<BeginStoryboard>
<Storyboard>
-->
<!-- 这个动画会把名为 ArrowRotateTransform 的旋转角度在0.3秒内变为180度 -->
<!--
<DoubleAnimation
Storyboard.TargetName="ArrowRotateTransform"
Storyboard.TargetProperty="Angle"
To="180"
Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
-->
<!-- 退出时(下拉框关闭),开始另一个动画故事板 -->
<!--
<BeginStoryboard>
<Storyboard>
-->
<!-- 这个动画会把旋转角度在0.3秒内恢复为0度 -->
<!--
<DoubleAnimation
Storyboard.TargetName="ArrowRotateTransform"
Storyboard.TargetProperty="Angle"
To="0"
Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>