1 Star 5 Fork 6

独立观察员 / WPFTemplateLib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
DictionaryComboBox.xaml 17.33 KB
一键复制 编辑 原始数据 按行查看 历史
独立观察员 提交于 2024-04-21 22:17 . [Break] 调整样式 Key
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:attached="clr-namespace:WPFTemplateLib.Attached"
xmlns:controls="clr-namespace:WPFTemplateLib.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="DictionaryCommon.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--#region 修改自 WPFUI(https://gitee.com/dlgcy/WPFUI) -->
<SolidColorBrush x:Key="ComboBox.Static.Background" Color="#337ab7"/>
<SolidColorBrush x:Key="ComboBox.Static.Over.Background" Color="#204d74"/>
<SolidColorBrush x:Key="ComboBox.Glyph" Color="White"/>
<SolidColorBrush x:Key="ComboBox.Font.A" Color="Black"/>
<SolidColorBrush x:Key="ComboBox.Background.B" Color="White"/>
<SolidColorBrush x:Key="ComboBox.Background.C" Color="#5CB85C"/>
<SolidColorBrush x:Key="ComboBox.Static.Over.Background.C" Color="#398439"/>
<SolidColorBrush x:Key="ComboBox.Background.D" Color="#5BC0DE"/>
<SolidColorBrush x:Key="ComboBox.Static.Over.Background.D" Color="#269ABC"/>
<SolidColorBrush x:Key="ComboBox.Background.E" Color="#F0AD4E"/>
<SolidColorBrush x:Key="ComboBox.Static.Over.Background.E" Color="#D58512"/>
<SolidColorBrush x:Key="ComboBox.Background.F" Color="#D9534F"/>
<SolidColorBrush x:Key="ComboBox.Static.Over.Background.F" Color="#AC2925"/>
<CornerRadius x:Key="ComboBox.CornerRadius">5</CornerRadius>
<Style x:Key="LibSty.WpfUi.TextBox.InComboBox.Editable" TargetType="{x:Type TextBox}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="MinWidth" Value="0"/>
<Setter Property="MinHeight" Value="0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="LibSty.WpfUi.ToggleButton.InComboBox" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="templateRoot" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{StaticResource ComboBox.CornerRadius}">
<Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="arrow" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z" Fill="{StaticResource ComboBox.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<ControlTemplate x:Key="LibTpl.WpfUi.ComboBox.Editable" TargetType="{x:Type ComboBox}">
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
</Grid.ColumnDefinitions>
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<controls:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
<Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<ScrollViewer x:Name="DropDownScrollViewer">
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ScrollViewer>
</Border>
</controls:SystemDropShadowChrome>
</Popup>
<ToggleButton x:Name="toggleButton" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource LibSty.WpfUi.ToggleButton.InComboBox}"
Foreground="White" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
<Border Grid.Column="0" x:Name="border" Background="{StaticResource ComboBox.Static.Background}" Margin="{TemplateBinding BorderThickness}"
CornerRadius="{StaticResource ComboBox.CornerRadius}">
<TextBox x:Name="PART_EditableTextBox" Style="{StaticResource LibSty.WpfUi.TextBox.InComboBox.Editable}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="true">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
<Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
<Setter Property="Color" TargetName="shadow" Value="#71000000"/>
</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 x:Key="LibSty.WpfUi.ComboBoxItem" TargetType="{x:Type ComboBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Padding" Value="4,1"/>
<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="{StaticResource FocusVisual}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="TextElement.FontWeight" TargetName="Bd" Value="Bold"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--PrimaryBox-->
<Style x:Key="LibSty.WpfUi.ComboBox.Primary" TargetType="{x:Type ComboBox}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Background}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="attached:WpfXamlPropProxy.MouseOverBackground" Value="{StaticResource ComboBox.Static.Over.Background}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Padding" Value="6,3,5,3"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="attached:WpfXamlPropProxy.CornerRadius" Value="5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid x:Name="templateRoot" SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
</Grid.ColumnDefinitions>
<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<controls:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
<Border x:Name="dropDownBorder" BorderBrush="#dddddd" BorderThickness="1"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<ScrollViewer x:Name="DropDownScrollViewer">
<Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
<Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ScrollViewer>
</Border>
</controls:SystemDropShadowChrome>
</Popup>
<ToggleButton x:Name="toggleButton" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource LibSty.WpfUi.ToggleButton.InComboBox}"
Foreground="White" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
<ContentPresenter x:Name="contentPresenter" Grid.Column="0" TextElement.Foreground="{StaticResource ComboBox.Glyph}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
HorizontalAlignment="Center" IsHitTestVisible="false" Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<Border Grid.Column="0" x:Name="proxy" Visibility="Collapsed" Background="{TemplateBinding attached:WpfXamlPropProxy.MouseOverBackground}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
<Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
<Setter Property="Color" TargetName="shadow" Value="#71000000"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Background" TargetName="toggleButton"
Value="{Binding Background, ElementName=proxy}"/>
</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>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="Template" Value="{StaticResource LibTpl.WpfUi.ComboBox.Editable}"/>
</Trigger>
</Style.Triggers>
</Style>
<!--SuccessBox-->
<Style x:Key="LibSty.WpfUi.ComboBox.Success" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource LibSty.WpfUi.ComboBox.Primary}">
<Setter Property="Background" Value="{StaticResource ComboBox.Background.C}"/>
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Background.C}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="attached:WpfXamlPropProxy.MouseOverBackground" Value="{StaticResource ComboBox.Static.Over.Background.C}"/>
</Style>
<!--InfoBox-->
<Style x:Key="LibSty.WpfUi.ComboBox.Info" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource LibSty.WpfUi.ComboBox.Primary}">
<Setter Property="Background" Value="{StaticResource ComboBox.Background.D}"/>
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Background.D}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="attached:WpfXamlPropProxy.MouseOverBackground" Value="{StaticResource ComboBox.Static.Over.Background.D}"/>
</Style>
<!--WarningBox-->
<Style x:Key="LibSty.WpfUi.ComboBox.Warning" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource LibSty.WpfUi.ComboBox.Primary}">
<Setter Property="Background" Value="{StaticResource ComboBox.Background.E}"/>
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Background.E}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="attached:WpfXamlPropProxy.MouseOverBackground" Value="{StaticResource ComboBox.Static.Over.Background.E}"/>
</Style>
<!--DangerBox-->
<Style x:Key="LibSty.WpfUi.ComboBox.Danger" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource LibSty.WpfUi.ComboBox.Primary}">
<Setter Property="Background" Value="{StaticResource ComboBox.Background.F}"/>
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Background.F}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="attached:WpfXamlPropProxy.MouseOverBackground" Value="{StaticResource ComboBox.Static.Over.Background.F}"/>
</Style>
<!--#endregion-->
</ResourceDictionary>
C#
1
https://gitee.com/dlgcy/WPFTemplateLib.git
git@gitee.com:dlgcy/WPFTemplateLib.git
dlgcy
WPFTemplateLib
WPFTemplateLib
master

搜索帮助