StyleComboBox.xaml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  3. <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
  4. <Grid>
  5. <Grid.ColumnDefinitions>
  6. <ColumnDefinition/>
  7. <ColumnDefinition Width="30"/>
  8. </Grid.ColumnDefinitions>
  9. <Border x:Name="Border"
  10. Grid.ColumnSpan="2"
  11. CornerRadius="5"
  12. BorderBrush="#59A862"
  13. BorderThickness="1"
  14. SnapsToDevicePixels="true">
  15. </Border>
  16. <Border Grid.Column="1"
  17. BorderBrush="#444" Name="ButtonBorder"
  18. CornerRadius="0" BorderThickness="0"
  19. Background="Transparent" />
  20. <Border Grid.Column="1">
  21. <Path x:Name="Arrow"
  22. 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"
  23. Fill="#59A862"
  24. Stretch="Fill"
  25. Height="7"
  26. Width="10"
  27. HorizontalAlignment="Center"
  28. VerticalAlignment="Center"/>
  29. </Border>
  30. </Grid>
  31. <ControlTemplate.Triggers>
  32. <Trigger Property="UIElement.IsMouseOver" Value="True">
  33. <Setter Property="Panel.Background" TargetName="ButtonBorder" Value="Transparent"/>
  34. </Trigger>
  35. <Trigger Property="ToggleButton.IsChecked" Value="True">
  36. <Setter Property="Panel.Background" TargetName="ButtonBorder" Value="Transparent"/>
  37. <Setter Property="Shape.Fill" TargetName="Arrow" Value="#498C51"/>
  38. </Trigger>
  39. <Trigger Property="UIElement.IsEnabled" Value="False">
  40. <Setter Property="Panel.Background" TargetName="Border" Value="#498C51"/>
  41. <Setter Property="Panel.Background" TargetName="ButtonBorder" Value="#498C51"/>
  42. <Setter Property="Border.BorderBrush" TargetName="ButtonBorder" Value="#498C51"/>
  43. <Setter Property="TextElement.Foreground" Value="#498C51"/>
  44. <Setter Property="Shape.Fill" TargetName="Arrow" Value="#498C51"/>
  45. </Trigger>
  46. </ControlTemplate.Triggers>
  47. </ControlTemplate>
  48. <ControlTemplate x:Key="ComboBoxTextBox" TargetType="{x:Type TextBox}">
  49. <Border x:Name="PART_ContentHost"
  50. Focusable="True"
  51. Background="{TemplateBinding Background}"/>
  52. </ControlTemplate>
  53. <Style TargetType="ComboBox">
  54. <Setter Property="UIElement.SnapsToDevicePixels" Value="True"/>
  55. <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/>
  56. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  57. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  58. <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
  59. <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
  60. <Setter Property="Height" Value="40"/>
  61. <Setter Property="Width" Value="250"/>
  62. <Setter Property="FontSize" Value="14"/>
  63. <Setter Property="Foreground" Value="#59A862"/>
  64. <Setter Property="HorizontalAlignment" Value="Center"/>
  65. <Setter Property="Margin" Value="0 10 0 0"/>
  66. <Setter Property="Cursor" Value="Hand"/>
  67. <Setter Property="Template">
  68. <Setter.Value>
  69. <ControlTemplate TargetType="ComboBox">
  70. <Grid>
  71. <ToggleButton x:Name="ToggleButton"
  72. Grid.Column="2"
  73. ClickMode="Press" Focusable="False"
  74. IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
  75. Template="{StaticResource ComboBoxToggleButton}"/>
  76. <ContentPresenter Name="ContentSite"
  77. Margin="5 0"
  78. IsHitTestVisible="False"
  79. HorizontalAlignment="Left" VerticalAlignment="Center"
  80. Content="{TemplateBinding ComboBox.SelectionBoxItem}"
  81. ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
  82. ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"/>
  83. <TextBox Name="PART_EditableTextBox" Margin="3 10"
  84. IsReadOnly="{TemplateBinding IsReadOnly}"
  85. Visibility="Hidden" Background="Transparent"
  86. HorizontalAlignment="Left" VerticalAlignment="Center"
  87. Focusable="True">
  88. <TextBox.Template>
  89. <ControlTemplate TargetType="TextBox" >
  90. <Border Name="PART_ContentHost" Focusable="False" VerticalAlignment="Center"/>
  91. </ControlTemplate>
  92. </TextBox.Template>
  93. </TextBox>
  94. <Popup Name="Popup" Placement="Bottom"
  95. Focusable="False" AllowsTransparency="True"
  96. IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"
  97. PopupAnimation="Slide">
  98. <Grid Name="DropDown" SnapsToDevicePixels="True"
  99. MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
  100. MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}">
  101. <Border Name="DropDownBorder"
  102. Background="White" Margin="1"
  103. CornerRadius="0" BorderThickness="0"
  104. BorderBrush="#498C51"/>
  105. <ScrollViewer Margin="4" SnapsToDevicePixels="True">
  106. <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
  107. </ScrollViewer>
  108. </Grid>
  109. </Popup>
  110. <Label x:Name="Watermark"
  111. VerticalAlignment="Center"
  112. HorizontalAlignment="Left"
  113. Foreground="#59A862"
  114. Visibility="Collapsed"
  115. Padding="10 0 0 0"
  116. Content="{TemplateBinding Tag}"
  117. FontSize="15"/>
  118. </Grid>
  119. <ControlTemplate.Triggers>
  120. <MultiTrigger>
  121. <MultiTrigger.Conditions>
  122. <Condition Property="Text" Value=""/>
  123. </MultiTrigger.Conditions>
  124. <Setter Property="Visibility" Value="Visible" TargetName="Watermark"/>
  125. </MultiTrigger>
  126. <Trigger Property="ItemsControl.HasItems" Value="False">
  127. <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/>
  128. </Trigger>
  129. <Trigger Property="UIElement.IsEnabled" Value="False">
  130. <Setter Property="TextElement.Foreground" Value="#498C51"/>
  131. </Trigger>
  132. <Trigger Property="ItemsControl.IsGrouping" Value="True">
  133. <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
  134. </Trigger>
  135. <Trigger Property="ComboBox.IsEditable" Value="True">
  136. <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
  137. <Setter Property="UIElement.Visibility" TargetName="PART_EditableTextBox" Value="Visible"/>
  138. <Setter Property="UIElement.Visibility" TargetName="ContentSite" Value="Hidden"/>
  139. </Trigger>
  140. </ControlTemplate.Triggers>
  141. </ControlTemplate>
  142. </Setter.Value>
  143. </Setter>
  144. </Style>
  145. </ResourceDictionary>