ComboBoxStyle.xaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  3. <ResourceDictionary.MergedDictionaries>
  4. <ResourceDictionary Source="AutoDisappearScrollViewerStyle.xaml" />
  5. </ResourceDictionary.MergedDictionaries>
  6. <PathGeometry x:Key="IsSelectedIcon" Figures="M416.058904 776.794805c-10.475586 0-20.951171-3.996011-28.943193-11.989055L131.272789 508.962827c-15.985066-15.985066-15.985066-41.901319 0-57.886385s41.901319-15.985066 57.886385 0l226.898707 226.898707 418.780899-418.780899c15.985066-15.985066 41.901319-15.985066 57.886385 0s15.985066 41.901319 0 57.886385L445.002097 764.80575C437.010075 772.797771 426.53449 776.794805 416.058904 776.794805z" />
  7. <PathGeometry x:Key="Arrow.Down" Figures="M7.41,8.58L12,13.17 16.59,8.58 18,10 12,16 6,10 7.41,8.58z" />
  8. <PathGeometry x:Key="Arrow.Up" Figures="M7.41,15.41L12,10.83 16.59,15.41 18,14 12,8 6,14 7.41,15.41z" />
  9. <!--#region ComboBoxStyle基样式-->
  10. <!-- ComboBox样式 add by zhidf 2015.12.31 -->
  11. <SolidColorBrush x:Key="BorderColor" Color="#00D3D6DB" />
  12. <SolidColorBrush x:Key="ComboBox.BorderBrush" Color="#ABADB3" />
  13. <SolidColorBrush x:Key="ComboBox.Popup.BorderBrush" Color="#C8C8C8" />
  14. <SolidColorBrush x:Key="ComboBox.Normal.Background" Color="#FFFFFF" />
  15. <SolidColorBrush x:Key="ComboBox.Disabled.Foreground" Color="#888" />
  16. <SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#00eeeeee" />
  17. <SolidColorBrush x:Key="ComboBox.Disabled.BorderBrush" Color="#00888888" />
  18. <SolidColorBrush x:Key="ComboBoxItem.MouseOver.Background" Color="#E2E2E2" />
  19. <SolidColorBrush x:Key="ComboBoxItem.MouseOver.Foreground" Color="#000000" />
  20. <ControlTemplate x:Key="ComboBoxToggleButtonTemplate" TargetType="ToggleButton">
  21. <Grid Background="Transparent" Margin="0,0,0,0">
  22. <Grid.ColumnDefinitions>
  23. <ColumnDefinition Width="*" />
  24. <ColumnDefinition Width="auto" />
  25. </Grid.ColumnDefinitions>
  26. <Border Name="Border" Grid.ColumnSpan="2"
  27. Background="{StaticResource ComboBox.Normal.Background}"
  28. BorderBrush="{StaticResource ComboBox.BorderBrush}"
  29. BorderThickness="1, 1, 1, 1" CornerRadius="0" SnapsToDevicePixels="True" UseLayoutRounding="True" />
  30. <Border Name="ButtonBorder" Grid.Column="1" Margin="1, 1, 1, 1"
  31. Background="{StaticResource ComboBox.Normal.Background}"
  32. Padding="5,0">
  33. <Path Name="Arrow" Grid.Column="1" Width="10"
  34. HorizontalAlignment="Center" VerticalAlignment="Center"
  35. Data="{StaticResource Arrow.Down}"
  36. SnapsToDevicePixels="True" Stretch="Uniform" Fill="{StaticResource ComboBox.BorderBrush}"
  37. UseLayoutRounding="True" />
  38. </Border>
  39. </Grid>
  40. <ControlTemplate.Triggers>
  41. <Trigger Property="UIElement.IsMouseOver" Value="True">
  42. <Setter TargetName="ButtonBorder" Property="Panel.Background" Value="WhiteSmoke" />
  43. </Trigger>
  44. <Trigger Property="ToggleButton.IsChecked" Value="True">
  45. <Setter TargetName="ButtonBorder" Property="Panel.Background" Value="WhiteSmoke" />
  46. <Setter TargetName="Arrow" Property="Data" Value="{StaticResource Arrow.Up}" />
  47. </Trigger>
  48. <Trigger Property="UIElement.IsEnabled" Value="False">
  49. <Setter TargetName="Border" Property="Panel.Background" Value="{StaticResource ComboBox.Disabled.Background}" />
  50. <Setter TargetName="Border" Property="Border.BorderBrush" Value="{StaticResource ComboBox.Disabled.BorderBrush}" />
  51. <Setter TargetName="ButtonBorder" Property="Panel.Background" Value="{StaticResource ComboBox.Disabled.Background}" />
  52. <Setter TargetName="ButtonBorder" Property="Border.BorderBrush" Value="{StaticResource ComboBox.Disabled.BorderBrush}" />
  53. <Setter Property="TextElement.Foreground" Value="{StaticResource ComboBox.Disabled.Foreground}" />
  54. <Setter TargetName="Arrow" Property="Stroke" Value="#999" />
  55. <Setter TargetName="Arrow" Property="StrokeThickness" Value="0" />
  56. </Trigger>
  57. </ControlTemplate.Triggers>
  58. </ControlTemplate>
  59. <Style x:Key="ComboBoxItemStyle1" TargetType="{x:Type ComboBoxItem}">
  60. <Setter Property="SnapsToDevicePixels" Value="True" />
  61. <Setter Property="Padding" Value="10,7,15,7" />
  62. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
  63. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
  64. <Setter Property="Background" Value="Transparent" />
  65. <Setter Property="BorderBrush" Value="Transparent" />
  66. <Setter Property="BorderThickness" Value="0" />
  67. <Setter Property="FontSize" Value="{Binding FontSize, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
  68. <Setter Property="Template">
  69. <Setter.Value>
  70. <ControlTemplate TargetType="{x:Type ComboBoxItem}">
  71. <Border x:Name="Bd"
  72. Background="{TemplateBinding Background}"
  73. BorderBrush="{TemplateBinding BorderBrush}"
  74. BorderThickness="{TemplateBinding BorderThickness}"
  75. Padding="{TemplateBinding Padding}"
  76. SnapsToDevicePixels="true" UseLayoutRounding="True">
  77. <Grid>
  78. <Grid.ColumnDefinitions>
  79. <ColumnDefinition Width="*" />
  80. <ColumnDefinition Width="auto" />
  81. </Grid.ColumnDefinitions>
  82. <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  83. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  84. SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  85. <Path Name="IsSelectIcon" Grid.Column="1" Width="11"
  86. HorizontalAlignment="Center" VerticalAlignment="Center"
  87. Data="{StaticResource IsSelectedIcon}"
  88. SnapsToDevicePixels="True" Stretch="Uniform"
  89. Fill="#00FFFFFF" StrokeThickness="1"
  90. UseLayoutRounding="True" />
  91. </Grid>
  92. </Border>
  93. <ControlTemplate.Triggers>
  94. <Trigger Property="IsEnabled" Value="False">
  95. <Setter Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
  96. </Trigger>
  97. <Trigger Property="IsMouseOver" Value="True">
  98. <Setter Property="Background" Value="{StaticResource ComboBoxItem.MouseOver.Background}" />
  99. <Setter Property="Foreground" Value="{StaticResource ComboBoxItem.MouseOver.Foreground}" />
  100. </Trigger>
  101. <Trigger Property="IsSelected" Value="True">
  102. <Setter Property="Background" Value="{StaticResource ComboBoxItem.MouseOver.Background}" />
  103. <Setter Property="Foreground" Value="{StaticResource ComboBoxItem.MouseOver.Foreground}" />
  104. <Setter TargetName="IsSelectIcon" Property="Fill" Value="{StaticResource ComboBoxItem.MouseOver.Foreground}" />
  105. </Trigger>
  106. </ControlTemplate.Triggers>
  107. </ControlTemplate>
  108. </Setter.Value>
  109. </Setter>
  110. </Style>
  111. <DropShadowBitmapEffect x:Key="shadow" Direction="285" Opacity="0.5" ShadowDepth="5"
  112. Softness="1" Color="Black" />
  113. <Style x:Key="DefaultComboBoxStyle" TargetType="{x:Type ComboBox}">
  114. <Setter Property="UIElement.SnapsToDevicePixels" Value="True" />
  115. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
  116. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
  117. <Setter Property="ScrollViewer.CanContentScroll" Value="True" />
  118. <Setter Property="TextElement.Foreground" Value="#000000" />
  119. <Setter Property="TextElement.FontSize" Value="12" />
  120. <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}" />
  121. <Setter Property="MinHeight" Value="20" />
  122. <Setter Property="Control.Template">
  123. <Setter.Value>
  124. <ControlTemplate TargetType="{x:Type ComboBox}">
  125. <Grid Width="{TemplateBinding Width}">
  126. <Grid.ColumnDefinitions>
  127. <ColumnDefinition Width="auto" />
  128. <ColumnDefinition Width="*" />
  129. </Grid.ColumnDefinitions>
  130. <Grid Grid.Column="1">
  131. <ToggleButton Name="ToggleButton" ClickMode="Press" Focusable="False"
  132. IsChecked="{Binding Path=IsDropDownOpen,
  133. RelativeSource={RelativeSource TemplatedParent},
  134. Mode=TwoWay}"
  135. Template="{StaticResource ComboBoxToggleButtonTemplate}" />
  136. <ContentPresenter Name="ContentSite" Margin="5, 3, 23, 3" HorizontalAlignment="Left" VerticalAlignment="Center"
  137. Content="{TemplateBinding ComboBox.SelectionBoxItem}"
  138. ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
  139. ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
  140. IsHitTestVisible="False" />
  141. <TextBox Name="PART_EditableTextBox" Margin="5, 3, 5, 3" HorizontalAlignment="Left"
  142. VerticalAlignment="Center" Background="Transparent" Focusable="True" IsReadOnly="False"
  143. Visibility="Hidden">
  144. <TextBox.Template>
  145. <ControlTemplate TargetType="TextBox">
  146. <Border x:Name="OuterBorder" Grid.Column="1" Width="100" HorizontalAlignment="Left"
  147. Background="Transparent" BorderBrush="#C8C8C8" BorderThickness="0" CornerRadius="0">
  148. <ScrollViewer x:Name="PART_ContentHost" Margin="0,0" VerticalAlignment="Center" />
  149. </Border>
  150. </ControlTemplate>
  151. </TextBox.Template>
  152. </TextBox>
  153. <!-- Popup showing items -->
  154. <Popup Name="Popup"
  155. MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
  156. MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}"
  157. AllowsTransparency="True" Focusable="False"
  158. IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"
  159. Placement="Bottom" PopupAnimation="Slide" HorizontalOffset="-1" VerticalOffset="1">
  160. <Grid Name="DropDown"
  161. Width="{TemplateBinding FrameworkElement.ActualWidth}"
  162. MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}"
  163. Margin="10,0,10,10" SnapsToDevicePixels="True">
  164. <Border Background="#FFFFFF" CornerRadius="15,15,2,2" SnapsToDevicePixels="True" UseLayoutRounding="True">
  165. <Border.Effect>
  166. <DropShadowEffect BlurRadius="12" Opacity="0.2" ShadowDepth="0" Color="Brown" />
  167. </Border.Effect>
  168. </Border>
  169. <Border Name="DropDownBorder" Background="#FFFFFF"
  170. BorderBrush="{StaticResource ComboBox.Popup.BorderBrush}"
  171. BorderThickness="1" CornerRadius="0" SnapsToDevicePixels="True" UseLayoutRounding="True" />
  172. <ScrollViewer Margin="0,0,0,0" SnapsToDevicePixels="True"
  173. Style="{DynamicResource AutoDisappearScrollViewerStyle}">
  174. <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
  175. </ScrollViewer>
  176. </Grid>
  177. </Popup>
  178. </Grid>
  179. </Grid>
  180. <ControlTemplate.Triggers>
  181. <Trigger Property="ItemsControl.HasItems" Value="False">
  182. <Setter TargetName="DropDownBorder" Property="FrameworkElement.MinHeight" Value="95" />
  183. </Trigger>
  184. <Trigger Property="UIElement.IsEnabled" Value="False">
  185. <Setter Property="TextElement.Foreground" Value="{StaticResource ComboBox.Disabled.Foreground}" />
  186. <Setter TargetName="PART_EditableTextBox" Property="Foreground" Value="{StaticResource ComboBox.Disabled.Foreground}" />
  187. </Trigger>
  188. <Trigger Property="ItemsControl.IsGrouping" Value="True">
  189. <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
  190. </Trigger>
  191. <Trigger Property="ComboBox.IsEditable" Value="True">
  192. <Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
  193. <Setter TargetName="PART_EditableTextBox" Property="UIElement.Visibility" Value="Visible" />
  194. <Setter TargetName="ContentSite" Property="UIElement.Visibility" Value="Hidden" />
  195. </Trigger>
  196. <Trigger Property="Validation.HasError" Value="True">
  197. <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
  198. </Trigger>
  199. </ControlTemplate.Triggers>
  200. </ControlTemplate>
  201. </Setter.Value>
  202. </Setter>
  203. <Setter Property="ItemContainerStyle" Value="{StaticResource ResourceKey=ComboBoxItemStyle1}" />
  204. </Style>
  205. <!--#endregion-->
  206. <!--#region 特殊样式-->
  207. <Style x:Key="New_ComboBox_Style" TargetType="ComboBox" BasedOn="{StaticResource ComboBoxBaseStyle}">
  208. </Style>
  209. </ResourceDictionary>