Files

253 lines
17 KiB
Plaintext
Raw Permalink Normal View History

2025-08-20 12:10:13 +08:00
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2026-02-20 15:31:44 +08:00
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
2026-01-02 17:30:41 +08:00
xmlns:assists="clr-namespace:Melskin.Assists"
xmlns:controls="clr-namespace:Melskin.Controls"
2026-02-20 15:31:44 +08:00
xmlns:converters="clr-namespace:Melskin.Converters">
2025-08-20 12:10:13 +08:00
<ResourceDictionary.MergedDictionaries>
2026-01-02 17:30:41 +08:00
<ResourceDictionary Source="/Melskin;component/Controls/ComboBox.xaml" />
2025-08-20 12:10:13 +08:00
</ResourceDictionary.MergedDictionaries>
2026-02-20 15:31:44 +08:00
<Style x:Key="MultiComboBoxItemStyle" TargetType="{x:Type ListBoxItem}">
2025-08-20 12:10:13 +08:00
<Setter Property="SnapsToDevicePixels" Value="True" />
2025-12-23 21:35:54 +08:00
<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}}}" />
2025-08-20 12:10:13 +08:00
<Setter Property="Background" Value="Transparent" />
2025-12-23 21:35:54 +08:00
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
2025-08-20 12:10:13 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
2025-12-23 21:35:54 +08:00
<Grid>
<!--<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" />-->
<Border
2026-02-20 15:31:44 +08:00
x:Name="Bd"
Padding="{TemplateBinding Padding}"
2025-12-23 21:35:54 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="True">
2025-12-23 21:35:54 +08:00
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
2026-02-20 15:31:44 +08:00
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2025-12-23 21:35:54 +08:00
</Border>
<Border
2026-02-20 15:31:44 +08:00
x:Name="Indicator"
2025-12-23 21:35:54 +08:00
CornerRadius="4"
2026-02-20 15:31:44 +08:00
Visibility="Hidden">
2025-12-23 21:35:54 +08:00
<Border
2026-02-20 15:31:44 +08:00
Width="4"
2026-01-02 17:30:30 +08:00
Margin="2,4"
2026-02-20 15:31:44 +08:00
HorizontalAlignment="Left"
Background="{DynamicResource PrimaryNormalBrush}"
CornerRadius="2" />
2025-12-23 21:35:54 +08:00
</Border>
<!--<controls:IconElement
x:Name="CheckMark"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontWeight="Bold"
Foreground="{DynamicResource PrimaryNormalBrush}"
Symbol="Check"
Visibility="Collapsed" />-->
</Grid>
2025-08-20 12:10:13 +08:00
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
2026-02-20 15:31:44 +08:00
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ControlBackgroundSelectedBrush}" />
<Setter TargetName="Indicator" Property="Visibility" Value="Visible" />
2025-08-20 12:10:13 +08:00
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
2026-02-20 15:31:44 +08:00
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ControlBackgroundHoverBrush}" />
2025-08-20 12:10:13 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-12-23 21:35:54 +08:00
<Style TargetType="{x:Type controls:MultiComboBox}">
2025-08-20 12:10:13 +08:00
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
2025-12-23 21:35:54 +08:00
<Setter Property="BorderBrush" Value="Transparent" />
2025-08-20 12:10:13 +08:00
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderThickness" Value="1" />
2026-02-22 20:03:42 +08:00
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="12,7" />
2025-08-20 12:10:13 +08:00
<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-12-23 21:35:54 +08:00
<ControlTemplate TargetType="{x:Type controls:MultiComboBox}">
2025-08-20 12:10:13 +08:00
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="10" />
</Grid.ColumnDefinitions>
2025-08-20 12:10:13 +08:00
<ToggleButton
2026-02-20 15:31:44 +08:00
x:Name="PART_ToggleButton"
Grid.Column="0"
Grid.ColumnSpan="2"
2025-08-20 12:10:13 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
2026-02-20 15:31:44 +08:00
Style="{DynamicResource ComboBoxToggleButton}" />
<Grid
2026-02-20 15:31:44 +08:00
x:Name="templateRoot"
Grid.Column="0"
2025-12-23 21:35:54 +08:00
Margin="{TemplateBinding BorderThickness}"
VerticalAlignment="Center"
2026-02-20 15:31:44 +08:00
ClipToBounds="True">
2025-08-20 12:10:13 +08:00
<!-- 占位符 水印 -->
<TextBlock
2026-02-20 15:31:44 +08:00
x:Name="PlaceholderTextBlock"
2025-12-23 21:35:54 +08:00
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
VerticalAlignment="Center"
2026-02-20 15:31:44 +08:00
Foreground="{DynamicResource TextPlaceholderBrush}"
IsHitTestVisible="False"
Text="{Binding PlaceHolderText, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<!-- 多选:无标签 -->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
2025-12-23 21:35:54 +08:00
<Condition Binding="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}}" Value="{x:Static SelectionMode.Multiple}" />
<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-12-23 21:35:54 +08:00
<Condition Binding="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}}" Value="{x:Static SelectionMode.Single}" />
<Condition Binding="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}}" Value="{x:Null}" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
2025-08-20 12:10:13 +08:00
<!-- 多选 Tag 列表 -->
<!--<ItemsControl x:Name="TagItemsControl" ItemsSource="{Binding SelectedItems, Mode=OneWay, RelativeSource={RelativeSource AncestorType=local:NeuComboBox}}">-->
2026-02-20 15:31:44 +08:00
<ItemsControl x:Name="TagItemsControl" ItemsSource="{Binding ElementName=PART_ListBox, Path=SelectedItems}">
<ItemsControl.Style>
<Style TargetType="ItemsControl">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
2025-12-23 21:35:54 +08:00
<DataTrigger Binding="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}}" Value="{x:Static SelectionMode.Multiple}">
<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>
<controls:Tag
2026-02-20 15:31:44 +08:00
Margin="1"
Closable="True"
2026-02-20 15:31:44 +08:00
Content="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ContentPresenter
2026-02-20 15:31:44 +08:00
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
2025-12-23 21:35:54 +08:00
Content="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}}"
ContentStringFormat="{Binding DisplayMemberPath, RelativeSource={RelativeSource TemplatedParent}}"
IsHitTestVisible="False"
Visibility="{Binding SelectionMode, RelativeSource={RelativeSource AncestorType=controls:MultiComboBox}, Converter={x:Static converters:ComparisionToVisibilityConverter.Instance}, ConverterParameter={x:Static SelectionMode.Single}}" />
2025-08-20 12:10:13 +08:00
</Grid>
<Popup
2026-02-20 15:31:44 +08:00
x:Name="dropDownBorder"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
MinWidth="{Binding ActualWidth, ElementName=PART_ToggleButton}"
2026-02-20 15:31:44 +08:00
Margin="-8"
assists:BehaviorAssist.SimulateNativeBehavior="True"
AllowsTransparency="True"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
2025-08-20 12:10:13 +08:00
Placement="Bottom"
2025-10-10 11:19:58 +08:00
PlacementTarget="{Binding ElementName=PART_ToggleButton}"
2025-08-20 12:10:13 +08:00
PopupAnimation="Slide"
2025-10-10 11:19:58 +08:00
StaysOpen="True"
2026-02-20 15:31:44 +08:00
VerticalOffset="4">
2025-08-20 12:10:13 +08:00
<Border
2026-02-20 15:31:44 +08:00
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
Margin="8"
2025-08-20 12:10:13 +08:00
Background="{DynamicResource BackgroundLayoutBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
2026-02-20 15:31:44 +08:00
Effect="{DynamicResource PopupShadow}">
2025-08-20 12:10:13 +08:00
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<!-- 用于 TextBox -->
<RowDefinition Height="*" />
<!-- 用于 ListBox占据剩余空间 -->
</Grid.RowDefinitions>
<TextBox
2026-02-20 15:31:44 +08:00
x:Name="PART_FilterTextBox"
2025-08-20 12:10:13 +08:00
Grid.Row="0"
Margin="6,6,6,2"
Padding="4,2"
VerticalAlignment="Top"
assists:InputAssist.Clearable="{TemplateBinding assists:InputAssist.Clearable}"
2026-02-20 15:31:44 +08:00
Text="{Binding FilterText, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding IsFilteringEnabled, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:BooleanToVisibilityConverter.CollapsedInstance}}">
2025-08-20 12:10:13 +08:00
<assists:InputAssist.Suffix>
2025-10-10 11:19:58 +08:00
<controls:IconElement
2026-02-20 15:31:44 +08:00
Width="16"
2025-10-10 11:19:58 +08:00
Height="16"
Margin="4,2,2,0"
2026-02-20 15:31:44 +08:00
Foreground="{DynamicResource TextSecondaryBrush}"
Symbol="Search" />
2025-08-20 12:10:13 +08:00
</assists:InputAssist.Suffix>
</TextBox>
<ListBox
2026-02-20 15:31:44 +08:00
x:Name="PART_ListBox"
Grid.Row="1"
2025-12-23 21:35:54 +08:00
Background="{DynamicResource BackgroundFloatingBrush}"
2025-08-20 12:10:13 +08:00
BorderThickness="0"
DisplayMemberPath="{Binding DisplayMemberPath, RelativeSource={RelativeSource TemplatedParent}}"
2025-12-23 21:35:54 +08:00
ItemContainerStyle="{StaticResource MultiComboBoxItemStyle}"
2025-08-20 12:10:13 +08:00
ItemsSource="{Binding FilteredItems, RelativeSource={RelativeSource TemplatedParent}}"
2026-02-20 15:31:44 +08:00
SelectionMode="{Binding SelectionMode, RelativeSource={RelativeSource TemplatedParent}}" />
2025-08-20 12:10:13 +08:00
</Grid>
</Border>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>