WPF CommonBox Style

<SolidColorBrush x:Key="ComboBoxItemBackground"
Color="#FF868A8D" />
<Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
<SolidColorBrush x:Key="ListBorder"
Color="#FF7F9DB9" />
<Style x:Key="ComboBoxReadonlyToggleButton"
TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle"
Value="true" />
<Setter Property="IsTabStop"
Value="false" />
<Setter Property="Focusable"
Value="false" />
<Setter Property="Width"
Value="Auto" />
<Setter Property="Height"
Value="Auto" />
<Setter Property="Background"
Value="Transparent" />
<Setter Property="ClickMode"
Value="Press" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border BorderThickness="{TemplateBinding BorderThickness}"
x:Name="Chrome"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="true">
<Grid Name="grid"
HorizontalAlignment="Right"
Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FF5A5757"
Offset="1" />
<GradientStop Color="#FFD6D6D6" />
</LinearGradientBrush>
</Grid.Background>
<Path x:Name="Arrow"
Data="{StaticResource DownArrowGeometry}"
Fill="#FF3D3636"
HorizontalAlignment="Center"
Margin="1,1,0,0"
VerticalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Fill"
TargetName="Arrow"
Value="#AFAFAF" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="true">
<Setter Property="Fill"
TargetName="Arrow"
Value="#AFAFAF" />
<Setter Property="Background"
TargetName="grid">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FF707070"
Offset="1" />
<GradientStop Color="#FF272323" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed"
Value="true">
<Setter Property="Fill"
TargetName="Arrow"
Value="#FFD6CF82" />
<Setter Property="Background"
TargetName="grid">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop Color="#FF9D9D9D"
Offset="1" />
<GradientStop Color="#FF0A0A0A" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="FocusVisualStyle"
Value="{x:Null}" />
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Background"
Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="BorderBrush"
Value="{StaticResource ListBorder}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Padding"
Value="1" />
<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="VerticalContentAlignment"
Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid SnapsToDevicePixels="true">
<Border x:Name="Bd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="1">
<Grid Grid.IsSharedSizeScope="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1" />
<ColumnDefinition Width="*" />
<ColumnDefinition SharedSizeGroup="ComboBoxButton"
Width="Auto" />
</Grid.ColumnDefinitions>
<Border x:Name="SelectedItemBorder"
Grid.ColumnSpan="2"
Margin="{TemplateBinding Padding}" />
<ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
Content="{TemplateBinding SelectionBoxItem}"
Grid.Column="1"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<ToggleButton Grid.ColumnSpan="3"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ComboBoxReadonlyToggleButton}" />
</Grid>
</Border>
<Popup x:Name="PART_Popup"
AllowsTransparency="true"
Focusable="false"
IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
Placement="Bottom">
<Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw"
Color="Transparent"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
MinWidth="{TemplateBinding ActualWidth}">
<Border x:Name="DropDownBorder"
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
BorderThickness="1"
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<ScrollViewer x:Name="DropDownScrollViewer" Template ="{DynamicResource ScrollViewerControlTemplate}" >
<Grid RenderOptions.ClearTypeHint="Enabled" >
<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>
</Microsoft_Windows_Themes:SystemDropShadowChrome>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelectionBoxHighlighted"
Value="true" />
<Condition Property="IsDropDownOpen"
Value="false" />
</MultiTrigger.Conditions>
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
</MultiTrigger>
<Trigger Property="IsSelectionBoxHighlighted"
Value="true">
<Setter Property="Background"
TargetName="SelectedItemBorder"
Value="{StaticResource ComboBoxItemBackground}" />
</Trigger>
<Trigger Property="HasDropShadow"
SourceName="PART_Popup"
Value="true">
<Setter Property="Margin"
TargetName="Shdw"
Value="0,0,5,5" />
<Setter Property="Color"
TargetName="Shdw"
Value="#71000000" />
</Trigger>
<Trigger Property="HasItems"
Value="false">
<Setter Property="MinHeight"
TargetName="DropDownBorder"
Value="95" />
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
<Setter Property="Background"
TargetName="Bd"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</Trigger>
<Trigger Property="IsGrouping"
Value="true">
<Setter Property="ScrollViewer.CanContentScroll"
Value="True " />
</Trigger>
<Trigger Property="ScrollViewer.CanContentScroll"
SourceName="DropDownScrollViewer"
Value="True">
<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="0,1" />
<Setter Property="Template"
Value="{StaticResource ComboBoxEditableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>

时间: 2024-11-05 22:00:49

WPF CommonBox Style的相关文章

WPF 样式(Style)初体验 (一) 作用域

刚刚接触WPF的开发,顿时对样式设计产生了兴趣.因为之前对CSS比较感兴趣,不难发现WPF的Style和CSS的模式很类似.下面我就根据自己初步的理解和CSS样式表对比做下总结,有理解不正确的地方还希望各位前辈指正. (1)全局样式控制 影响的是整个项目的样式,我们可以在App.xaml文件里定义全局的样式(这里就类似于我们在一个web的项目中添加一个全局的CSS文件,然后在每个页面引用CSS样式): <Application.Resources> <Style TargetType=&

WPF CHECKBOX STYLE

源自 http://www.wpfhelper.com/index.php/android-ui-for-wpf/23-modern-ui-for-wpf/android-ui-for-wpf/26-wpf-checkbox-style-inspired-by-android CheckBoxStyleXAMLWPF How create WPF CheckBox style and customize it. The CheckBox style is inspired by Android

WPF 中style文件的引用

原文:WPF 中style文件的引用 总结一下WPF中Style样式的引用方法: 一,内联样式: 直接设置控件的Height.Width.Foreground.HorizontalAlignment.VerticalAlignment等属性.以设置一个Botton控件的样式为例,如: 复制代码 <Grid x:Name="ContentPanel" > <Button Content="Button" Name="btnDemo"

从0 开始 WPF MVVM 企业级框架实现与说明 ---- 第五讲 WPF中 Style

Style这个东西几乎是无处不在,这个类似于web开发中的css样式,想要做一个很丰富的UI,这个东西是必不可少的,我也不是专业的UI开发者,这边只能介绍Style在WPF中的用法 下面有一个下载地址,这个demo还可以供初学者学习 Style基本用法: 在WPF中我们可以使用Style来设置控件的某些属性值,并使该设置影响到指定范围内的所有该类控件或影响指定的某一控件,比如说我们想将窗口中的所有按钮都保持某一种风格,那么我们可以设置一个Style,而不必分别设置每个按钮的风格. Style是作

[WPF] 为Style 里的button添加鼠标点击响应事件

一个TabControl, 用的是PagedTabControl style, 在style中有个button, button在style里已经写了click事件,但是现在还需要加上一段功能,就是在响应事件之前对界面作一下判断.该怎么办呢?先看代码: 1. 控件XAML部分代码(位于文件form_loadatorigin.xaml): <!-- Form Body --> <TabControl x:Name="formLoadUnload" Style="

wpf 将Style应用到 ListView 中的 ListViewItem 元素

例: 为每个条目元素设置右键菜单 1. 新建右键菜单元素和样式元素 注意: 同时设置样式元素的 TargetType 属性和 x:Key 属性, 将样式元素限定为应用于 ListViewItem 类型元素并且需要显示指定才可应用 <Window.Resources> <ContextMenu x:Key="ContextMenuTest"> <MenuItem Header="右键菜单1"/> <MenuItem Heade

WPF系列 Style

    参考 WPF: Customize your Application with Styles and Control Templates (Part 2 of 2)

WPF Expander style

<!--ExpanderStyle--> <Style x:Key="ExpanderStyleOne" TargetType="{x:Type Expander}"> <Setter Property="Foreground" Value="#FF217cb5"/> <Setter Property="FontFamily" Value="宋体"

wpf button style IsMouseOver

<Style x:Key="workButtonStyle" TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="FontSize" Value="20"/> </