Files
Shrlalgo.RvKits/NeoUI/NeoUI/Controls/FlattenComboBox.xaml

200 lines
11 KiB
Plaintext
Raw Normal View History

2025-07-31 20:12:01 +08:00
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- 只显示当前选项 -->
<Style TargetType="{x:Type ComboBox}" x:Key="ComboBoxPreview">
<Setter Property="FocusVisualStyle" Value="{StaticResource 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"
SnapsToDevicePixels="true"
x:Name="templateRoot">
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
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
<Style TargetType="{x:Type ToggleButton}" x:Key="FlattenComboBoxToggleButton">
<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"
SnapsToDevicePixels="true"
x:Name="border">
<!-- 下拉箭头 -->
<Border
BorderBrush="Transparent"
BorderThickness="1"
HorizontalAlignment="Right"
Margin="0"
SnapsToDevicePixels="true"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"
x:Name="splitBorder">
<Path
Data="M 0,0 L 4,3 L 8,0"
HorizontalAlignment="Center"
Margin="0"
2025-08-12 23:08:54 +08:00
Stroke="{DynamicResource TextPrimaryBrush}"
2025-07-31 20:12:01 +08:00
StrokeThickness="1"
VerticalAlignment="Center"
x:Name="arrow" />
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">
2025-08-12 23:08:54 +08:00
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource BorderGradientBrush}" />
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">
2025-08-12 23:08:54 +08:00
<Setter Property="Fill" 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
<!-- 默认样式 -->
<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="*" />
<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
AllowsTransparency="true"
Grid.ColumnSpan="2"
IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Margin="-8"
Placement="Bottom"
PopupAnimation="Slide"
VerticalOffset="4"
x:Name="PART_Popup">
<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"
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">
<Canvas
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="0"
x:Name="canvas">
<Rectangle
Fill="{Binding Background, ElementName=dropDownBorder}"
Height="{Binding ActualHeight, ElementName=dropDownBorder}"
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"
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}"
Grid.Column="0"
Grid.ColumnSpan="2"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource FlattenComboBoxToggleButton}"
x:Name="toggleButton" />
<ContentPresenter
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Grid.Column="0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
IsHitTestVisible="false"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
2025-07-11 09:20:23 +08:00
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
2025-07-31 20:12:24 +08:00
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
2025-07-11 09:20:23 +08:00
</Trigger>
<Trigger Property="HasItems" Value="false">
2025-07-31 20:12:01 +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>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
2025-07-31 20:12:01 +08:00
<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>
2025-07-31 20:12:01 +08:00
<Style TargetType="{x:Type ComboBox}" x:Key="FlattenComboBox">
<Setter Property="FocusVisualStyle" Value="{StaticResource 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>