更新
This commit is contained in:
264
AntdWpf/Styles/ComboBox.xaml
Normal file
264
AntdWpf/Styles/ComboBox.xaml
Normal file
@@ -0,0 +1,264 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:AntdWpf.Controls"
|
||||
xmlns:helpers="clr-namespace:AntdWpf.Helpers">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Converters.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Animations.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Control.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Input.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style x:Key="Ant.ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
|
||||
<Setter Property="OverridesDefaultStyle" Value="True" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ToggleButton}">
|
||||
<Grid x:Name="Root"
|
||||
Opacity="0.45"
|
||||
Background="{TemplateBinding Background}">
|
||||
<ContentPresenter x:Name="Content"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
|
||||
<ContentPresenter.RenderTransform>
|
||||
<RotateTransform />
|
||||
</ContentPresenter.RenderTransform>
|
||||
</ContentPresenter>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.3" />
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState x:Name="Normal" />
|
||||
<VisualState x:Name="MouseOver">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="Root"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.65" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Pressed">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="Root"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="1" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Disabled" />
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup x:Name="CheckStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.3" />
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState x:Name="Checked">
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetName="Content"
|
||||
Storyboard.TargetProperty="RenderTransform.Angle"
|
||||
To="180" />
|
||||
</Storyboard>
|
||||
</VisualState>
|
||||
<VisualState x:Name="Unchecked" />
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Ant.ComboBox" BasedOn="{StaticResource Ant.Input}" TargetType="{x:Type ComboBox}">
|
||||
<Setter Property="MaxDropDownHeight" Value="250" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ComboBox}">
|
||||
<Grid>
|
||||
<!-- Input Effect -->
|
||||
<Border x:Name="Effect"
|
||||
Opacity="0"
|
||||
Focusable="False"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{DynamicResource OutlineThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:Control.CornerRadius}"
|
||||
Margin="{Binding BorderThickness, Mode=OneWay, RelativeSource={RelativeSource Self},
|
||||
Converter={StaticResource ThicknessReverseConverter}}" />
|
||||
<!-- Input -->
|
||||
<controls:Border x:Name="Border"
|
||||
UseLayoutRounding="True"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
BorderStyle="{TemplateBinding helpers:Control.BorderStyle}"
|
||||
CornerRadius="{TemplateBinding helpers:Control.CornerRadius}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!-- Input -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<!-- Suffix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ContentPresenter x:Name="Prefix"
|
||||
Grid.Column="0"
|
||||
Margin="1 0 5 0"
|
||||
Focusable="False"
|
||||
Content="{TemplateBinding helpers:Input.Prefix}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
<!-- Placeholder -->
|
||||
<TextBlock x:Name="Placeholder"
|
||||
Grid.Column="1"
|
||||
Focusable="False"
|
||||
Visibility="Collapsed"
|
||||
Text="{TemplateBinding helpers:Input.Placeholder}"
|
||||
Foreground="{TemplateBinding helpers:Input.PlaceholderBrush}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
|
||||
<!-- Editable TextBox -->
|
||||
<TextBox x:Name="PART_EditableTextBox"
|
||||
Grid.Column="1"
|
||||
Visibility="Collapsed"
|
||||
Style="{StaticResource Ant.EditableTextBox}" />
|
||||
<!-- ContentSite -->
|
||||
<ContentPresenter x:Name="ContentSite"
|
||||
Grid.Column="1"
|
||||
IsHitTestVisible="False"
|
||||
Content="{TemplateBinding SelectionBoxItem}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
|
||||
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" />
|
||||
<!-- DropDownToggle -->
|
||||
<ToggleButton x:Name="DropDownToggle"
|
||||
Grid.Column="1"
|
||||
Grid.ColumnSpan="2"
|
||||
Padding="5 0 1 0"
|
||||
IsTabStop="False"
|
||||
Focusable="False"
|
||||
Background="Transparent"
|
||||
HorizontalContentAlignment="Right"
|
||||
Style="{StaticResource Ant.ComboBoxToggleButton}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
|
||||
<controls:Icon Type="down" />
|
||||
</ToggleButton>
|
||||
<!-- Clear -->
|
||||
<controls:Icon x:Name="Clear"
|
||||
Grid.Column="2"
|
||||
Margin="5 0 1 0"
|
||||
Type="close"
|
||||
Focusable="False"
|
||||
Visibility="Collapsed"
|
||||
helpers:Input.ClearEnabled="True"
|
||||
Style="{StaticResource Ant.Clearable}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Grid>
|
||||
</controls:Border>
|
||||
<!-- Popup -->
|
||||
<Popup x:Name="PART_Popup"
|
||||
Focusable="False"
|
||||
VerticalOffset="4"
|
||||
Placement="Bottom"
|
||||
PopupAnimation="Slide"
|
||||
AllowsTransparency="True"
|
||||
IsOpen="{TemplateBinding IsDropDownOpen}">
|
||||
<Border Margin="8"
|
||||
Background="{TemplateBinding Background}"
|
||||
MaxHeight="{TemplateBinding MaxDropDownHeight}"
|
||||
CornerRadius="{TemplateBinding helpers:Control.CornerRadius}"
|
||||
Width="{Binding ActualWidth, Mode=OneWay, ElementName=Border}">
|
||||
<Border.Effect>
|
||||
<DropShadowEffect ShadowDepth="0" Opacity="0.15" BlurRadius="8"/>
|
||||
</Border.Effect>
|
||||
<ScrollViewer>
|
||||
<ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="FocusStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.3" />
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState x:Name="Focused" Storyboard="{StaticResource Ant.InputAnimating}" />
|
||||
<VisualState x:Name="Unfocused" />
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger SourceName="Prefix" Property="Content" Value="{x:Null}">
|
||||
<Setter TargetName="Prefix" Property="Visibility" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEditable" Value="True">
|
||||
<Setter TargetName="ContentSite" Property="Visibility" Value="Hidden" />
|
||||
<Setter TargetName="DropDownToggle" Property="Background" Value="{x:Null}" />
|
||||
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />
|
||||
</Trigger>
|
||||
<!-- Fix Focused -->
|
||||
<Trigger SourceName="PART_EditableTextBox" Property="IsFocused" Value="True">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource OutlineBrush}" />
|
||||
</Trigger>
|
||||
<MultiDataTrigger>
|
||||
<MultiDataTrigger.Conditions>
|
||||
<Condition Binding="{Binding Text, Mode=OneWay, ElementName=PART_EditableTextBox}" Value="" />
|
||||
<Condition Binding="{Binding SelectedItem, Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="{x:Null}" />
|
||||
</MultiDataTrigger.Conditions>
|
||||
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
|
||||
</MultiDataTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="helpers:Input.Clearable" Value="True" />
|
||||
<Condition SourceName="Placeholder" Property="Visibility" Value="Collapsed" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter TargetName="Clear" Property="Visibility" Value="Visible" />
|
||||
<Setter TargetName="DropDownToggle" Property="Content" Value="" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Ant.ComboBoxItem" BasedOn="{StaticResource Ant.TextElement}" TargetType="{x:Type ComboBoxItem}">
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||
<Setter Property="SnapsToDevicePixels" Value="True" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
<Setter Property="Padding" Value="{DynamicResource ItemPadding}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
|
||||
<Border Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
|
||||
<ContentPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource ItemMouseOverBackground}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="FontWeight" Value="SemiBold" />
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundBrushLight}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{DynamicResource DisabledBrush}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user