Files
ShrlAlgoToolkit/Melskin/Controls/FlattenComboBox.xaml

215 lines
12 KiB
Plaintext
Raw Normal View History

<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"
xmlns:controls="clr-namespace:Melskin.Controls">
<ResourceDictionary.MergedDictionaries>
2026-01-02 17:30:41 +08:00
<ResourceDictionary Source="/Melskin;component/Themes/Animations.xaml" />
<ResourceDictionary Source="/Melskin;component/Controls/IconElement.xaml" />
</ResourceDictionary.MergedDictionaries>
2025-07-31 20:12:01 +08:00
<!-- 只显示当前选项 -->
2026-02-20 15:31:44 +08:00
<Style x:Key="ComboBoxPreviewStyle" TargetType="{x:Type ComboBox}">
2025-08-26 21:33:20 +08:00
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
2025-07-31 20:12:01 +08:00
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="4,2" />
2025-07-11 09:20:23 +08:00
2025-07-31 20:12:01 +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" />
2025-07-11 09:20:23 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
2025-07-31 20:12:01 +08:00
<Grid
2026-02-20 15:31:44 +08:00
x:Name="templateRoot"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Background}"
IsHitTestVisible="False"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="true">
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-02-20 15:31:44 +08:00
x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
2025-07-31 20:12:01 +08:00
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2025-07-11 09:20:23 +08:00
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-07-31 20:12:01 +08:00
2026-02-20 15:31:44 +08:00
<Style x:Key="FlattenComboBoxToggleButtonStyle" TargetType="{x:Type ToggleButton}">
2025-07-31 20:12:01 +08:00
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="ClickMode" Value="Press" />
2025-07-11 09:20:23 +08:00
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
2025-07-31 20:12:01 +08:00
<Border
2026-02-20 15:31:44 +08:00
x:Name="border"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="0"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="true">
2025-07-31 20:12:01 +08:00
<!-- 下拉箭头 -->
<Border
2026-02-20 15:31:44 +08:00
x:Name="splitBorder"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
Margin="0"
HorizontalAlignment="Right"
2025-07-31 20:12:01 +08:00
BorderBrush="Transparent"
BorderThickness="1"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="true">
<controls:IconElement
2026-02-20 15:31:44 +08:00
x:Name="arrow"
Foreground="{DynamicResource TextPrimaryBrush}"
RenderTransformOrigin="0.5,0.5"
SnapsToDevicePixels="false"
2026-02-20 15:31:44 +08:00
Symbol="KeyboardArrowDown">
<controls:IconElement.RenderTransform>
<RotateTransform Angle="0" />
</controls:IconElement.RenderTransform>
</controls:IconElement>
2025-07-11 09:20:23 +08:00
</Border>
</Border>
<ControlTemplate.Triggers>
2025-07-31 20:12:01 +08:00
<Trigger Property="IsMouseOver" Value="true" />
<!-- 缩减阴影,下压效果 -->
<Trigger Property="IsPressed" Value="true" />
2025-07-11 09:20:23 +08:00
<Trigger Property="IsChecked" Value="True">
2026-02-20 15:31:44 +08:00
<Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource BorderGradientBrush}" />
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource ExpandRotateStoryboard}" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource CollapseRotateStoryboard}" />
</Trigger.ExitActions>
2025-07-11 09:20:23 +08:00
</Trigger>
2025-07-31 20:12:01 +08:00
<!-- 按钮禁用效果 -->
2025-07-11 09:20:23 +08:00
<Trigger Property="IsEnabled" Value="false">
2026-02-20 15:31:44 +08:00
<Setter TargetName="arrow" Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter TargetName="border" Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
2025-07-11 09:20:23 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-07-31 20:12:01 +08:00
<!-- 默认样式 -->
2026-02-20 15:31:44 +08:00
<ControlTemplate x:Key="FlattenComboBoxTemplate" TargetType="{x:Type ComboBox}">
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
2025-07-11 09:20:23 +08:00
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="*" />
2026-02-20 15:31:44 +08:00
<ColumnDefinition Width="0" MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<Popup
2026-02-20 15:31:44 +08:00
x:Name="PART_Popup"
2026-01-02 17:30:30 +08:00
Grid.ColumnSpan="2"
Margin="-8"
2026-02-20 15:31:44 +08:00
AllowsTransparency="true"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
2025-07-31 20:12:01 +08:00
Placement="Bottom"
PopupAnimation="Slide"
2026-02-20 15:31:44 +08:00
VerticalOffset="4">
2025-07-31 20:12:01 +08:00
<Border
2026-02-20 15:31:44 +08:00
x:Name="dropDownBorder"
MinWidth="{Binding ActualWidth, ElementName=templateRoot}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
Margin="8"
2025-08-12 23:08:54 +08:00
Background="{DynamicResource BackgroundLayoutBrush}"
BorderBrush="{DynamicResource BorderNormalBrush}"
2025-07-31 20:12:01 +08:00
BorderThickness="1"
2026-02-20 15:31:44 +08:00
CornerRadius="4">
<ScrollViewer x:Name="DropDownScrollViewer" Margin="4,3">
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
2025-07-31 20:12:01 +08:00
<Canvas
2026-02-20 15:31:44 +08:00
x:Name="canvas"
Width="0"
2025-07-31 20:12:01 +08:00
Height="0"
HorizontalAlignment="Left"
2026-02-20 15:31:44 +08:00
VerticalAlignment="Top">
2025-07-31 20:12:01 +08:00
<Rectangle
2026-02-20 15:31:44 +08:00
x:Name="opaqueRect"
2026-01-02 17:30:30 +08:00
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
2026-02-20 15:31:44 +08:00
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
Fill="{Binding Background, ElementName=dropDownBorder}" />
2025-07-11 09:20:23 +08:00
</Canvas>
2025-07-31 20:12:01 +08:00
<ItemsPresenter
2026-02-20 15:31:44 +08:00
x:Name="ItemsPresenter"
2025-07-31 20:12:01 +08:00
KeyboardNavigation.DirectionalNavigation="Contained"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2025-07-11 09:20:23 +08:00
</Grid>
</ScrollViewer>
</Border>
</Popup>
2025-07-31 20:12:01 +08:00
<ToggleButton
2026-02-20 15:31:44 +08:00
x:Name="toggleButton"
Grid.Column="0"
Grid.ColumnSpan="2"
2025-07-31 20:12:01 +08:00
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
2026-02-20 15:31:44 +08:00
Style="{StaticResource FlattenComboBoxToggleButtonStyle}" />
2025-07-31 20:12:01 +08:00
<ContentPresenter
2026-02-20 15:31:44 +08:00
x:Name="contentPresenter"
Grid.Column="0"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
2025-07-31 20:12:01 +08:00
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="false"
2026-02-20 15:31:44 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
2025-07-11 09:20:23 +08:00
</Grid>
<ControlTemplate.Triggers>
2026-02-20 15:31:44 +08:00
<Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="true">
<Setter TargetName="dropDownBorder" Property="Effect" Value="{DynamicResource PopupShadow}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="HasItems" Value="false">
2026-02-20 15:31:44 +08:00
<Setter TargetName="dropDownBorder" Property="Height" Value="95" />
2025-07-11 09:20:23 +08:00
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
2025-07-31 20:12:01 +08:00
<Condition Property="IsGrouping" Value="true" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" />
2025-07-11 09:20:23 +08:00
</MultiTrigger.Conditions>
2025-07-31 20:12:01 +08:00
<Setter Property="ScrollViewer.CanContentScroll" Value="false" />
2025-07-11 09:20:23 +08:00
</MultiTrigger>
2026-02-20 15:31:44 +08:00
<Trigger SourceName="DropDownScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false">
<Setter TargetName="opaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter TargetName="opaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
2025-07-11 09:20:23 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2026-02-20 15:31:44 +08:00
<Style x:Key="FlattenComboBoxStyle" TargetType="{x:Type ComboBox}">
2025-08-26 21:33:20 +08:00
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
2025-08-12 23:08:54 +08:00
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
2025-07-31 20:12:01 +08:00
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="4,2" />
<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 FlattenComboBoxTemplate}" />
2025-07-11 09:20:23 +08:00
</Style>
</ResourceDictionary>