功能完善
This commit is contained in:
550
NeuWPF/NeoUI/Controls/ComboBoxStyle.xaml
Normal file
550
NeuWPF/NeoUI/Controls/ComboBoxStyle.xaml
Normal file
@@ -0,0 +1,550 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:svd="clr-namespace:NeumUI.Controls.Decorations"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="FlattenTextBox.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<!-- 按钮高亮 -->
|
||||
<Storyboard x:Key="Button.FocusEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="border"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0.8" />
|
||||
<BooleanAnimationUsingKeyFrames
|
||||
Duration="0"
|
||||
Storyboard.TargetName="border"
|
||||
Storyboard.TargetProperty="ShaderEnabled">
|
||||
<DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
|
||||
</BooleanAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
<!-- 按钮取消高亮 -->
|
||||
<Storyboard x:Key="Button.LeaveEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="border"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0" />
|
||||
<BooleanAnimationUsingKeyFrames
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="border"
|
||||
Storyboard.TargetProperty="ShaderEnabled">
|
||||
<DiscreteBooleanKeyFrame KeyTime="0:0:0.2" Value="False" />
|
||||
</BooleanAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
<!-- 按钮按下 -->
|
||||
<Storyboard x:Key="Button.PressEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0"
|
||||
Storyboard.TargetName="border"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0.4" />
|
||||
</Storyboard>
|
||||
|
||||
<Style TargetType="{x:Type ToggleButton}" x:Key="ComboBoxToggleButton">
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="ClickMode" Value="Press" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<svd:EmbossBorder
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
Intensity="0"
|
||||
ShaderEnabled="False"
|
||||
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"
|
||||
Stroke="{DynamicResource TextPrimaryBrush}"
|
||||
StrokeThickness="1"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="arrow" />
|
||||
</Border>
|
||||
</svd:EmbossBorder>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource BorderGradientBrush}" />
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard Storyboard="{StaticResource Button.FocusEffect}" x:Name="showEffectBegin" />
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<BeginStoryboard Storyboard="{StaticResource Button.LeaveEffect}" />
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
<!-- 缩减阴影,下压效果 -->
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard Storyboard="{StaticResource Button.PressEffect}" x:Name="pressBegin" />
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<RemoveStoryboard BeginStoryboardName="pressBegin" />
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource BorderGradientBrush}" />
|
||||
</Trigger>
|
||||
<!-- 按钮禁用效果 -->
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- 可编辑样式 -->
|
||||
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="ComboBoxEditableTemplate">
|
||||
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<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
|
||||
Background="{DynamicResource BackgroundLayoutBrush}"
|
||||
BorderBrush="{DynamicResource BorderNormalBrush}"
|
||||
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" />
|
||||
</Canvas>
|
||||
<ItemsPresenter
|
||||
KeyboardNavigation.DirectionalNavigation="Contained"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
x:Name="ItemsPresenter" />
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
||||
</Popup>
|
||||
<ToggleButton
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Margin="-4"
|
||||
Style="{StaticResource ComboBoxToggleButton}"
|
||||
x:Name="toggleButton" />
|
||||
<Border
|
||||
Grid.Column="0"
|
||||
Margin="{TemplateBinding BorderThickness}"
|
||||
x:Name="border">
|
||||
<TextBox
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
Padding="6,4"
|
||||
Style="{StaticResource FlattenTextBox}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="PART_EditableTextBox" />
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Opacity" TargetName="border" Value="0.56" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocusWithin" Value="True" />
|
||||
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
|
||||
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="True" />
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
|
||||
</MultiTrigger>
|
||||
<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}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<!-- 默认控件样式 -->
|
||||
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="ComboBoxTemplate">
|
||||
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<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
|
||||
Background="{DynamicResource BackgroundLayoutBrush}"
|
||||
BorderBrush="{DynamicResource BorderNormalBrush}"
|
||||
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" />
|
||||
</Canvas>
|
||||
<ItemsPresenter
|
||||
KeyboardNavigation.DirectionalNavigation="Contained"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
x:Name="ItemsPresenter" />
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
||||
</Popup>
|
||||
<ToggleButton
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Margin="-4"
|
||||
Style="{StaticResource ComboBoxToggleButton}"
|
||||
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" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
|
||||
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="True" />
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
|
||||
</MultiTrigger>
|
||||
<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}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style TargetType="{x:Type ComboBox}" x:Key="ComboBoxDefault">
|
||||
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
|
||||
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Margin" Value="4" />
|
||||
<Setter Property="Padding" Value="10,8" />
|
||||
|
||||
<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 ComboBoxTemplate}" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsEditable" Value="True">
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Padding" Value="3" />
|
||||
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
<!-- 默认下拉样式 -->
|
||||
<Style BasedOn="{StaticResource ComboBoxDefault}" TargetType="{x:Type ComboBox}" />
|
||||
|
||||
<!-- 内容样式 -->
|
||||
<Style TargetType="{x:Type ComboBoxItem}">
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<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}}}" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
|
||||
<Grid Margin="0,1">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="True"
|
||||
x:Name="Bd">
|
||||
<ContentPresenter
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Border>
|
||||
<!-- 选中标记 -->
|
||||
<Border
|
||||
CornerRadius="4"
|
||||
Visibility="Hidden"
|
||||
x:Name="box">
|
||||
<Border
|
||||
Background="{DynamicResource PrimaryNormalBrush}"
|
||||
CornerRadius="2"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="2,4"
|
||||
Width="4" />
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource TextDisabledBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Visibility" TargetName="box" Value="Visible" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource BackgroundFloatingBrush}" />
|
||||
</Trigger>
|
||||
<!--<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="Bd"
|
||||
Value="{StaticResource FocusBorderBrush}"/>
|
||||
</Trigger>-->
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- 工具栏下拉Toggle -->
|
||||
<Style TargetType="{x:Type ToggleButton}" x:Key="ToolbarComboBoxToggleButton">
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="ClickMode" Value="Press" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Border
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="4"
|
||||
Margin="4"
|
||||
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"
|
||||
Stroke="{DynamicResource TextPrimaryBrush}"
|
||||
StrokeThickness="1"
|
||||
VerticalAlignment="Center"
|
||||
x:Name="arrow" />
|
||||
</Border>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryNormalBrush}" />
|
||||
</Trigger>
|
||||
<!-- 下压效果 -->
|
||||
<Trigger Property="IsPressed" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryFocusedBrush}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource PrimaryFocusedBrush}" />
|
||||
</Trigger>
|
||||
<!-- 按钮禁用效果 -->
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Fill" TargetName="arrow" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Background" TargetName="border" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
<!-- 工具栏默认样式 -->
|
||||
<ControlTemplate TargetType="{x:Type ComboBox}" x:Key="ToolBarComboBoxTemplate">
|
||||
<Grid SnapsToDevicePixels="True" x:Name="templateRoot">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<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
|
||||
Background="{DynamicResource BackgroundLayoutBrush}"
|
||||
BorderBrush="{DynamicResource BorderNormalBrush}"
|
||||
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" />
|
||||
</Canvas>
|
||||
<ItemsPresenter
|
||||
KeyboardNavigation.DirectionalNavigation="Contained"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
x:Name="ItemsPresenter" />
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
||||
</Popup>
|
||||
<ToggleButton
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Margin="-4"
|
||||
Style="{StaticResource ToolbarComboBoxToggleButton}"
|
||||
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" />
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
|
||||
<Setter Property="Effect" TargetName="dropDownBorder" Value="{DynamicResource PopupShadow}" />
|
||||
</Trigger>
|
||||
<Trigger Property="HasItems" Value="False">
|
||||
<Setter Property="Height" TargetName="dropDownBorder" Value="95" />
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsGrouping" Value="True" />
|
||||
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="False" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
|
||||
</MultiTrigger>
|
||||
<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}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<!-- 工具栏下拉样式 -->
|
||||
<Style
|
||||
BasedOn="{StaticResource ComboBoxDefault}"
|
||||
TargetType="{x:Type ComboBox}"
|
||||
x:Key="{x:Static ToolBar.ComboBoxStyleKey}">
|
||||
<Setter Property="Margin" Value="2" />
|
||||
<Setter Property="Padding" Value="4,2" />
|
||||
<Setter Property="Template" Value="{StaticResource ToolBarComboBoxTemplate}" />
|
||||
</Style>
|
||||
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user