Files
ShrlAlgoToolkit/NeoUI/Melskin/Controls/FlattenComboBox.xaml

215 lines
12 KiB
Plaintext
Raw Normal View History

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2026-01-02 17:30:30 +08:00
xmlns:controls="clr-namespace:VariaStudio.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
2026-01-02 17:30:30 +08:00
<ResourceDictionary Source="/VariaStudio;component/Themes/Animations.xaml" />
<ResourceDictionary Source="/VariaStudio;component/Controls/IconElement.xaml" />
</ResourceDictionary.MergedDictionaries>
2025-07-31 20:12:01 +08:00
<!-- 只显示当前选项 -->
2026-01-02 17:30:30 +08:00
<Style TargetType="{x:Type ComboBox}" x:Key="ComboBoxPreviewStyle">
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
Background="{TemplateBinding Background}"
IsHitTestVisible="False"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="true"
x:Name="templateRoot">
2025-07-31 20:12:01 +08:00
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
2026-01-02 17:30:30 +08:00
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
2025-07-11 09:20:23 +08:00
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2025-07-31 20:12:01 +08:00
2026-01-02 17:30:30 +08:00
<Style TargetType="{x:Type ToggleButton}" x:Key="FlattenComboBoxToggleButtonStyle">
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
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="0"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="true"
x:Name="border">
2025-07-31 20:12:01 +08:00
<!-- 下拉箭头 -->
<Border
BorderBrush="Transparent"
BorderThickness="1"
2026-01-02 17:30:30 +08:00
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"
2026-01-02 17:30:30 +08:00
Symbol="KeyboardArrowDown"
x:Name="arrow">
<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-01-02 17:30:30 +08:00
<Setter Property="BorderBrush" TargetName="border" 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-01-02 17:30:30 +08:00
<Setter Property="Foreground" TargetName="arrow" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" TargetName="border" 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-01-02 17:30:30 +08:00
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="FlattenComboBoxTemplate">
<Grid SnapsToDevicePixels="true" x:Name="templateRoot">
2025-07-11 09:20:23 +08:00
<Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<ColumnDefinition Width="*" />
2026-01-02 17:30:30 +08:00
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
2025-07-11 09:20:23 +08:00
</Grid.ColumnDefinitions>
2025-07-31 20:12:01 +08:00
<Popup
2025-12-23 21:35:54 +08:00
AllowsTransparency="true"
2026-01-02 17:30:30 +08:00
Grid.ColumnSpan="2"
2025-12-23 21:35:54 +08:00
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
2026-01-02 17:30:30 +08:00
Margin="-8"
2025-07-31 20:12:01 +08:00
Placement="Bottom"
PopupAnimation="Slide"
2026-01-02 17:30:30 +08:00
VerticalOffset="4"
x:Name="PART_Popup">
2025-07-31 20:12:01 +08:00
<Border
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-01-02 17:30:30 +08:00
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">
2025-07-31 20:12:01 +08:00
<Canvas
Height="0"
HorizontalAlignment="Left"
2026-01-02 17:30:30 +08:00
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
2025-07-31 20:12:01 +08:00
<Rectangle
2026-01-02 17:30:30 +08:00
Fill="{Binding Background, ElementName=dropDownBorder}"
2025-12-23 21:35:54 +08:00
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
2026-01-02 17:30:30 +08:00
Width="{Binding ActualWidth, ElementName=dropDownBorder}"
x:Name="opaqueRect" />
2025-07-11 09:20:23 +08:00
</Canvas>
2025-07-31 20:12:01 +08:00
<ItemsPresenter
KeyboardNavigation.DirectionalNavigation="Contained"
2026-01-02 17:30:30 +08:00
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
x:Name="ItemsPresenter" />
2025-07-11 09:20:23 +08:00
</Grid>
</ScrollViewer>
</Border>
</Popup>
2025-07-31 20:12:01 +08:00
<ToggleButton
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
Grid.ColumnSpan="2"
2025-07-31 20:12:01 +08:00
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
2026-01-02 17:30:30 +08:00
Style="{StaticResource FlattenComboBoxToggleButtonStyle}"
x:Name="toggleButton" />
2025-07-31 20:12:01 +08:00
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
2026-01-02 17:30:30 +08:00
Grid.Column="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
2025-07-31 20:12:01 +08:00
IsHitTestVisible="false"
2026-01-02 17:30:30 +08:00
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
2025-07-11 09:20:23 +08:00
</Grid>
<ControlTemplate.Triggers>
2026-01-02 17:30:30 +08:00
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="HasItems" Value="false">
2026-01-02 17:30:30 +08:00
<Setter Property="Height" TargetName="dropDownBorder" 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-01-02 17:30:30 +08:00
<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}" />
2025-07-11 09:20:23 +08:00
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
2026-01-02 17:30:30 +08:00
<Style TargetType="{x:Type ComboBox}" x:Key="FlattenComboBoxStyle">
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>