Files
ShrlAlgoToolkit/Melskin/Controls/Cascader.xaml

283 lines
18 KiB
Plaintext
Raw Normal View History

2025-09-04 22:39:00 +08:00
<ResourceDictionary
2025-08-20 12:10:35 +08:00
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"
xmlns:converters="clr-namespace:Melskin.Converters"
2026-02-20 15:31:44 +08:00
xmlns:internal="clr-namespace:Melskin.Converters.Internal">
2025-08-20 12:10:35 +08:00
2025-09-04 22:39:00 +08:00
<ResourceDictionary.MergedDictionaries>
2026-01-02 17:30:41 +08:00
<ResourceDictionary Source="/Melskin;component/Themes/Animations.xaml" />
2025-09-04 22:39:00 +08:00
</ResourceDictionary.MergedDictionaries>
2026-02-20 15:31:44 +08:00
<Style x:Key="DefaultCascaderPanelStyle" TargetType="ListBox">
2025-08-20 12:10:35 +08:00
<!--<Setter Property="ItemContainerStyle" Value="{DynamicResource DefaultCascaderListBoxItemStyle}" />-->
<Setter Property="Background" Value="{DynamicResource BackgroundFloatingBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="10,4" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
2025-10-10 11:19:58 +08:00
<!-- <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> -->
2025-08-20 12:10:35 +08:00
<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="VerticalContentAlignment" Value="Center" />
<Setter Property="AlternationCount" Value="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count}" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- 核心修正:使用 TextBlock 并通过 MultiBinding 设置 Text -->
<TextBlock Grid.Column="0" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding Converter="{x:Static internal:PropertyValueConverter.Instance}">
<!-- 第一个绑定:当前的数据项 -->
<Binding Path="." />
<!-- 第二个绑定:从祖先 Cascader 获取 DisplayMemberPath -->
<Binding Path="DisplayMemberPath" RelativeSource="{RelativeSource AncestorType=controls:Cascader}" />
2025-08-20 12:10:35 +08:00
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<controls:IconElement
2026-02-20 15:31:44 +08:00
x:Name="Arrow"
2025-08-20 12:10:35 +08:00
Grid.Column="1"
2026-02-20 15:31:44 +08:00
Width="8"
2025-08-20 12:10:35 +08:00
Height="8"
2026-02-20 15:31:44 +08:00
Foreground="{DynamicResource TextPrimaryBrush}"
Symbol="KeyboardArrowRight"
2026-02-20 15:31:44 +08:00
Visibility="Hidden" />
2025-08-20 12:10:35 +08:00
</Grid>
<DataTemplate.Triggers>
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{x:Static internal:HasChildrenMultiConverter.Instance}">
<Binding Path="." />
<Binding Path="SubmenuMemberPath" RelativeSource="{RelativeSource AncestorType=controls:Cascader}" />
2025-08-20 12:10:35 +08:00
</MultiBinding>
</DataTrigger.Binding>
2026-02-20 15:31:44 +08:00
<Setter TargetName="Arrow" Property="Visibility" Value="Visible" />
2025-08-20 12:10:35 +08:00
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border
2026-02-20 15:31:44 +08:00
x:Name="Bd"
2025-08-20 12:10:35 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="true">
2025-08-20 12:10:35 +08:00
<ScrollViewer Focusable="false">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
2026-02-20 15:31:44 +08:00
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
2025-08-20 12:10:35 +08:00
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="true" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="false" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type controls:Cascader}">
2025-08-20 12:10:35 +08:00
<Setter Property="BorderThickness" Value="1" />
<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:35 +08:00
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
2025-12-23 21:35:54 +08:00
<Setter Property="Padding" Value="10,6" />
<Setter Property="FontSize" Value="14" />
2025-08-20 12:10:35 +08:00
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="assists:InputAssist.Clearable" Value="True" />
2025-12-23 21:35:54 +08:00
<Setter Property="assists:InputAssist.PlaceholderText" Value="请选择..." />
2025-08-20 12:10:35 +08:00
<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="PanelStyle" Value="{StaticResource DefaultCascaderPanelStyle}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:Cascader}">
2026-02-20 15:31:44 +08:00
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
2025-08-20 12:10:35 +08:00
<ToggleButton
2026-02-20 15:31:44 +08:00
x:Name="PART_ToggleButton"
2025-08-20 12:10:35 +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}" />
<TextBlock
2026-01-02 17:30:30 +08:00
Margin="{TemplateBinding Padding}"
2026-02-20 15:31:44 +08:00
VerticalAlignment="Center"
IsHitTestVisible="False"
Text="{Binding SelectedText, RelativeSource={RelativeSource AncestorType=controls:Cascader}}"
2026-02-20 15:31:44 +08:00
TextTrimming="CharacterEllipsis" />
2025-08-20 12:10:35 +08:00
<TextBlock
2026-02-20 15:31:44 +08:00
x:Name="Placeholder"
2025-10-10 11:19:58 +08:00
Margin="{TemplateBinding Padding}"
2025-12-23 21:35:54 +08:00
Padding="3"
2025-10-10 11:19:58 +08:00
VerticalAlignment="Center"
2026-02-20 15:31:44 +08:00
Foreground="{DynamicResource TextPlaceholderBrush}"
IsHitTestVisible="False"
Text="{Binding Path=(assists:InputAssist.PlaceholderText), RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:Cascader}}">
2025-08-20 12:10:35 +08:00
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<DataTrigger Binding="{Binding SelectedText, RelativeSource={RelativeSource AncestorType=controls:Cascader}}" Value="">
2025-08-20 12:10:35 +08:00
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<Popup
2026-02-20 15:31:44 +08:00
x:Name="PART_Popup"
Margin="-8"
assists:BehaviorAssist.SimulateNativeBehavior="True"
2025-08-20 12:10:35 +08:00
AllowsTransparency="True"
IsOpen="{Binding IsChecked, ElementName=PART_ToggleButton}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=PART_ToggleButton}"
PopupAnimation="Slide"
2026-02-20 15:31:44 +08:00
StaysOpen="True">
2025-08-20 12:10:35 +08:00
<Border
2026-02-20 15:31:44 +08:00
x:Name="PART_Border"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
MaxHeight="300"
Margin="8"
Background="{DynamicResource BackgroundFloatingBrush}"
2025-08-20 12:10:35 +08:00
BorderBrush="{DynamicResource BorderNormalBrush}"
BorderThickness="1"
CornerRadius="4"
Effect="{DynamicResource PopupShadow}"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="True">
2025-08-20 12:10:35 +08:00
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox
2026-02-20 15:31:44 +08:00
x:Name="PART_SearchBox"
2025-08-20 12:10:35 +08:00
Grid.Row="0"
Margin="4"
2026-02-20 15:31:44 +08:00
Text="{Binding SearchText, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}">
2025-08-20 12:10:35 +08:00
<assists:InputAssist.Suffix>
<controls:IconElement
2026-02-20 15:31:44 +08:00
Width="16"
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:35 +08:00
</assists:InputAssist.Suffix>
</TextBox>
<Grid Grid.Row="1">
<ScrollViewer
2026-02-20 15:31:44 +08:00
x:Name="PART_CascadingView"
2025-08-20 12:10:35 +08:00
HorizontalScrollBarVisibility="Auto"
2026-02-20 15:31:44 +08:00
VerticalScrollBarVisibility="Disabled">
2025-08-20 12:10:35 +08:00
<ContentPresenter Content="{TemplateBinding CascadingPanel}" />
</ScrollViewer>
<!-- 改造搜索结果列表 -->
<ListBox
2026-02-20 15:31:44 +08:00
x:Name="PART_SearchResultsView"
2025-08-20 12:10:35 +08:00
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding FilteredItemsSource, RelativeSource={RelativeSource TemplatedParent}}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
2026-02-20 15:31:44 +08:00
Visibility="Collapsed">
2025-08-20 12:10:35 +08:00
<ListBox.ItemTemplate>
<DataTemplate>
<!-- 使用一个完全透明的按钮来承载内容和命令 -->
<Button
2026-02-20 15:31:44 +08:00
Padding="4,2"
2026-01-02 17:30:30 +08:00
HorizontalContentAlignment="Stretch"
2026-02-20 15:31:44 +08:00
Command="{Binding RelativeSource={RelativeSource AncestorType=controls:Cascader}, Path=SelectSearchResultCommand}"
CommandParameter="{Binding}">
2025-08-20 12:10:35 +08:00
<Button.Template>
<ControlTemplate TargetType="Button">
<Border
2026-02-20 15:31:44 +08:00
x:Name="Bd"
2025-08-20 12:10:35 +08:00
Padding="{TemplateBinding Padding}"
2026-02-20 15:31:44 +08:00
Background="Transparent">
2025-08-20 12:10:35 +08:00
<ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<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:35 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
2025-10-10 11:19:58 +08:00
<!-- 按钮的内容就是之前定义的文本 -->
2025-08-20 12:10:35 +08:00
<TextBlock
Text="{Binding DisplayText}"
TextTrimming="CharacterEllipsis"
ToolTip="{Binding DisplayText}" />
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
2025-12-23 21:35:54 +08:00
2025-08-20 12:10:35 +08:00
</Border>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
2025-12-23 21:35:54 +08:00
<Setter Property="Background" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryFocusedBrush}" />
2025-08-20 12:10:35 +08:00
</Trigger>
2025-12-23 21:35:54 +08:00
2025-08-20 12:10:35 +08:00
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
2025-08-20 12:10:35 +08:00
</Trigger>
<Trigger Property="IsDropDownOpen" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
2025-08-20 12:10:35 +08:00
</Trigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
2025-09-04 22:39:00 +08:00
<Condition Binding="{Binding Path=SearchText, RelativeSource={RelativeSource Self}, Converter={x:Static converters:NullOrEmptyConverter.NotInstance}}" Value="True" />
2025-08-20 12:10:35 +08:00
</MultiDataTrigger.Conditions>
2026-02-20 15:31:44 +08:00
<Setter TargetName="PART_CascadingView" Property="Visibility" Value="Collapsed" />
<Setter TargetName="PART_SearchResultsView" Property="Visibility" Value="Visible" />
2025-08-20 12:10:35 +08:00
</MultiDataTrigger>
<Trigger Property="IsSearchable" Value="False">
2026-02-20 15:31:44 +08:00
<Setter TargetName="PART_SearchBox" Property="Visibility" Value="Collapsed" />
<Setter TargetName="PART_Border" Property="Background" Value="Transparent" />
<Setter TargetName="PART_Border" Property="BorderThickness" Value="0" />
2025-08-20 12:10:35 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>