resources/xaml/styles/ComboBoxStyle.xaml
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- Modern ComboBox Style --> <Style x:Key="ModernComboBoxStyle" TargetType="ComboBox"> <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ControlForegroundBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="FontFamily" Value="Segoe UI"/> <Setter Property="FontSize" Value="12"/> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="Padding" Value="8,4,8,4"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <Grid> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" SnapsToDevicePixels="True"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <ContentPresenter x:Name="contentPresenter" Grid.Column="0" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" IsHitTestVisible="False" SnapsToDevicePixels="True"/> <ToggleButton x:Name="toggleButton" Grid.Column="0" Grid.ColumnSpan="2" Background="Transparent" BorderBrush="Transparent" BorderThickness="0" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Focusable="False" ClickMode="Press"> <ToggleButton.Template> <ControlTemplate TargetType="ToggleButton"> <Border Background="Transparent"/> </ControlTemplate> </ToggleButton.Template> </ToggleButton> <Path x:Name="arrow" Grid.Column="1" Data="M 0 0 L 4 4 L 8 0 Z" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,8,0" IsHitTestVisible="False"/> </Grid> </Border> <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" PopupAnimation="Slide"> <Border x:Name="dropDownBorder" Background="{DynamicResource ControlBackgroundBrush}" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="1" CornerRadius="4" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"> <ScrollViewer x:Name="DropDownScrollViewer"> <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="True"/> </ScrollViewer> </Border> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource AccentBrush}"/> </Trigger> <Trigger Property="IsFocused" Value="True"> <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource AccentBrush}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/> <Setter Property="Opacity" Value="0.6"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- ComboBoxItem Style --> <Style TargetType="ComboBoxItem"> <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ControlForegroundBrush}"/> <Setter Property="Padding" Value="8,6,8,6"/> <Setter Property="FontFamily" Value="Segoe UI"/> <Setter Property="FontSize" Value="12"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBoxItem"> <Border x:Name="border" Background="{TemplateBinding Background}" BorderThickness="0" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True"> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="True"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource ItemHoverBrush}"/> <!-- Hover keeps control foreground since ItemHover is subtle --> </Trigger> <Trigger Property="IsHighlighted" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource ItemHoverBrush}"/> <!-- Highlighted keeps control foreground since ItemHover is subtle --> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource SelectionBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource SelectionForegroundBrush}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/> <Setter Property="Opacity" Value="0.6"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> |