close
如果你想要直接修改ComboBox背景顏色為自訂義漸層顏色,
你應該會跟我遇到一樣的狀況,怎麼改都沒有作用@@
1: <ComboBox Background="Yellow">
2: <ComboBox.Resources> 3: <!-- color of ComboBoxItem -->4: <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Yellow" />
5: <!-- Mouse over color of ComboBoxItem -->6: <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
7: </ComboBox.Resources> 8: <ComboBoxItem>One</ComboBoxItem> 9: <ComboBoxItem>Two</ComboBoxItem> 10: <ComboBoxItem>Three</ComboBoxItem> 11: </ComboBox>在元件上方按下滑鼠右鍵,選擇<編輯範本>
用預設值就可以,所以直接按下<確定>
1: <Window.Resources>2: <Style x:Key="FocusVisual">
3: <Setter Property="Control.Template">
4: <Setter.Value> 5: <ControlTemplate>6: <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
7: </ControlTemplate> 8: </Setter.Value> 9: </Setter> 10: </Style>11: <LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0">
12: <GradientStop Color="#FFF0F0F0" Offset="0.0"/>
13: <GradientStop Color="#FFE5E5E5" Offset="1.0"/>
14: </LinearGradientBrush>15: <SolidColorBrush x:Key="ComboBox.Static.Border" Color="#FFACACAC"/>
16: <SolidColorBrush x:Key="ComboBox.Static.Editable.Background" Color="#FFFFFFFF"/>
17: <SolidColorBrush x:Key="ComboBox.Static.Editable.Border" Color="#FFABADB3"/>
18: <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Background" Color="Transparent"/>
19: <SolidColorBrush x:Key="ComboBox.Static.Editable.Button.Border" Color="Transparent"/>
20: <SolidColorBrush x:Key="ComboBox.MouseOver.Glyph" Color="#FF000000"/>
21: <LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
22: <GradientStop Color="#FFECF4FC" Offset="0.0"/>
23: <GradientStop Color="#FFDCECFC" Offset="1.0"/>
24: </LinearGradientBrush>25: <SolidColorBrush x:Key="ComboBox.MouseOver.Border" Color="#FF7EB4EA"/>
26: <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Background" Color="#FFFFFFFF"/>
27: <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Border" Color="#FF7EB4EA"/>
28: <LinearGradientBrush x:Key="ComboBox.MouseOver.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
29: <GradientStop Color="#FFEBF4FC" Offset="0.0"/>
30: <GradientStop Color="#FFDCECFC" Offset="1.0"/>
31: </LinearGradientBrush>32: <SolidColorBrush x:Key="ComboBox.MouseOver.Editable.Button.Border" Color="#FF7EB4EA"/>
33: <SolidColorBrush x:Key="ComboBox.Pressed.Glyph" Color="#FF000000"/>
34: <LinearGradientBrush x:Key="ComboBox.Pressed.Background" EndPoint="0,1" StartPoint="0,0">
35: <GradientStop Color="#FFDAECFC" Offset="0.0"/>
36: <GradientStop Color="#FFC4E0FC" Offset="1.0"/>
37: </LinearGradientBrush>38: <SolidColorBrush x:Key="ComboBox.Pressed.Border" Color="#FF569DE5"/>
39: <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Background" Color="#FFFFFFFF"/>
40: <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Border" Color="#FF569DE5"/>
41: <LinearGradientBrush x:Key="ComboBox.Pressed.Editable.Button.Background" EndPoint="0,1" StartPoint="0,0">
42: <GradientStop Color="#FFDAEBFC" Offset="0.0"/>
43: <GradientStop Color="#FFC4E0FC" Offset="1.0"/>
44: </LinearGradientBrush>45: <SolidColorBrush x:Key="ComboBox.Pressed.Editable.Button.Border" Color="#FF569DE5"/>
46: <SolidColorBrush x:Key="ComboBox.Disabled.Glyph" Color="#FFBFBFBF"/>
47: <SolidColorBrush x:Key="ComboBox.Disabled.Background" Color="#FFF0F0F0"/>
48: <SolidColorBrush x:Key="ComboBox.Disabled.Border" Color="#FFD9D9D9"/>
49: <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Background" Color="#FFFFFFFF"/>
50: <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Border" Color="#FFBFBFBF"/>
51: <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Background" Color="Transparent"/>
52: <SolidColorBrush x:Key="ComboBox.Disabled.Editable.Button.Border" Color="Transparent"/>
53: <SolidColorBrush x:Key="ComboBox.Static.Glyph" Color="#FF606060"/>
54: <Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
55: <Setter Property="OverridesDefaultStyle" Value="true"/>
56: <Setter Property="IsTabStop" Value="false"/>
57: <Setter Property="Focusable" Value="false"/>
58: <Setter Property="ClickMode" Value="Press"/>
59: <Setter Property="Template">
60: <Setter.Value>61: <ControlTemplate TargetType="{x:Type ToggleButton}">
62: <Border x:Name="templateRoot" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource ComboBox.Static.Background}" SnapsToDevicePixels="true">
63: <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
64: <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.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
65: </Border> 66: </Border> 67: <ControlTemplate.Triggers> 68: <MultiDataTrigger> 69: <MultiDataTrigger.Conditions>70: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
71: <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="false"/>
72: <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="false"/>
73: <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="true"/>
74: </MultiDataTrigger.Conditions>75: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Background}"/>
76: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Static.Editable.Border}"/>
77: <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Background}"/>
78: <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Static.Editable.Button.Border}"/>
79: </MultiDataTrigger>80: <Trigger Property="IsMouseOver" Value="true">
81: <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.MouseOver.Glyph}"/>
82: </Trigger> 83: <MultiDataTrigger> 84: <MultiDataTrigger.Conditions>85: <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
86: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
87: </MultiDataTrigger.Conditions>88: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Background}"/>
89: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Border}"/>
90: </MultiDataTrigger> 91: <MultiDataTrigger> 92: <MultiDataTrigger.Conditions>93: <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true"/>
94: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
95: </MultiDataTrigger.Conditions>96: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Background}"/>
97: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.MouseOver.Editable.Border}"/>
98: <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Background}"/>
99: <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.MouseOver.Editable.Button.Border}"/>
100: </MultiDataTrigger>101: <Trigger Property="IsPressed" Value="true">
102: <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Pressed.Glyph}"/>
103: </Trigger> 104: <MultiDataTrigger> 105: <MultiDataTrigger.Conditions>106: <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
107: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
108: </MultiDataTrigger.Conditions>109: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Background}"/>
110: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Border}"/>
111: </MultiDataTrigger> 112: <MultiDataTrigger> 113: <MultiDataTrigger.Conditions>114: <Condition Binding="{Binding IsPressed, RelativeSource={RelativeSource Self}}" Value="true"/>
115: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
116: </MultiDataTrigger.Conditions>117: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Background}"/>
118: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Pressed.Editable.Border}"/>
119: <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Background}"/>
120: <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Pressed.Editable.Button.Border}"/>
121: </MultiDataTrigger>122: <Trigger Property="IsEnabled" Value="false">
123: <Setter Property="Fill" TargetName="arrow" Value="{StaticResource ComboBox.Disabled.Glyph}"/>
124: </Trigger> 125: <MultiDataTrigger> 126: <MultiDataTrigger.Conditions>127: <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
128: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="false"/>
129: </MultiDataTrigger.Conditions>130: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Background}"/>
131: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Border}"/>
132: </MultiDataTrigger> 133: <MultiDataTrigger> 134: <MultiDataTrigger.Conditions>135: <Condition Binding="{Binding IsEnabled, RelativeSource={RelativeSource Self}}" Value="false"/>
136: <Condition Binding="{Binding IsEditable, RelativeSource={RelativeSource AncestorType={x:Type ComboBox}}}" Value="true"/>
137: </MultiDataTrigger.Conditions>138: <Setter Property="Background" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Background}"/>
139: <Setter Property="BorderBrush" TargetName="templateRoot" Value="{StaticResource ComboBox.Disabled.Editable.Border}"/>
140: <Setter Property="Background" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Background}"/>
141: <Setter Property="BorderBrush" TargetName="splitBorder" Value="{StaticResource ComboBox.Disabled.Editable.Button.Border}"/>
142: </MultiDataTrigger> 143: </ControlTemplate.Triggers> 144: </ControlTemplate> 145: </Setter.Value> 146: </Setter> 147: </Style>148: <ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ComboBox}">
149: <Grid x:Name="templateRoot" SnapsToDevicePixels="true">
150: <Grid.ColumnDefinitions>151: <ColumnDefinition Width="*"/>
152: <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
153: </Grid.ColumnDefinitions>154: <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">
155: <Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
156: <Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
157: <ScrollViewer x:Name="DropDownScrollViewer">
158: <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
159: <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
160: <Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
161: </Canvas>162: <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
163: </Grid> 164: </ScrollViewer> 165: </Border> 166: </Themes:SystemDropShadowChrome> 167: </Popup>168: <ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
169: <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
170: </Grid> 171: <ControlTemplate.Triggers>172: <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
173: <Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
174: <Setter Property="Color" TargetName="shadow" Value="#71000000"/>
175: </Trigger>176: <Trigger Property="HasItems" Value="false">
177: <Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
178: </Trigger> 179: <MultiTrigger> 180: <MultiTrigger.Conditions>181: <Condition Property="IsGrouping" Value="true"/>
182: <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
183: </MultiTrigger.Conditions>184: <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
185: </MultiTrigger>186: <Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
187: <Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
188: <Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
189: </Trigger> 190: </ControlTemplate.Triggers> 191: </ControlTemplate>192: <SolidColorBrush x:Key="TextBox.Static.Background" Color="#FFFFFFFF"/>
193: <Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
194: <Setter Property="OverridesDefaultStyle" Value="true"/>
195: <Setter Property="AllowDrop" Value="true"/>
196: <Setter Property="MinWidth" Value="0"/>
197: <Setter Property="MinHeight" Value="0"/>
198: <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
199: <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
200: <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
201: <Setter Property="Template">
202: <Setter.Value>203: <ControlTemplate TargetType="{x:Type TextBox}">
204: <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
205: </ControlTemplate> 206: </Setter.Value> 207: </Setter> 208: </Style>209: <ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
210: <Grid x:Name="templateRoot" SnapsToDevicePixels="true">
211: <Grid.ColumnDefinitions>212: <ColumnDefinition Width="*"/>
213: <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
214: </Grid.ColumnDefinitions>215: <Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
216: <Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
217: <Border x:Name="dropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
218: <ScrollViewer x:Name="DropDownScrollViewer">
219: <Grid x:Name="grid" RenderOptions.ClearTypeHint="Enabled">
220: <Canvas x:Name="canvas" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
221: <Rectangle x:Name="opaqueRect" Fill="{Binding Background, ElementName=dropDownBorder}" Height="{Binding ActualHeight, ElementName=dropDownBorder}" Width="{Binding ActualWidth, ElementName=dropDownBorder}"/>
222: </Canvas>223: <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
224: </Grid> 225: </ScrollViewer> 226: </Border> 227: </Themes:SystemDropShadowChrome> 228: </Popup>229: <ToggleButton x:Name="toggleButton" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
230: <Border x:Name="border" Background="{StaticResource TextBox.Static.Background}" Margin="{TemplateBinding BorderThickness}">
231: <TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
232: </Border> 233: </Grid> 234: <ControlTemplate.Triggers>235: <Trigger Property="IsEnabled" Value="false">
236: <Setter Property="Opacity" TargetName="border" Value="0.56"/>
237: </Trigger>238: <Trigger Property="IsKeyboardFocusWithin" Value="true">
239: <Setter Property="Foreground" Value="Black"/>
240: </Trigger>241: <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
242: <Setter Property="Margin" TargetName="shadow" Value="0,0,5,5"/>
243: <Setter Property="Color" TargetName="shadow" Value="#71000000"/>
244: </Trigger>245: <Trigger Property="HasItems" Value="false">
246: <Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
247: </Trigger> 248: <MultiTrigger> 249: <MultiTrigger.Conditions>250: <Condition Property="IsGrouping" Value="true"/>
251: <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
252: </MultiTrigger.Conditions>253: <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
254: </MultiTrigger>255: <Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
256: <Setter Property="Canvas.Top" TargetName="opaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
257: <Setter Property="Canvas.Left" TargetName="opaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
258: </Trigger> 259: </ControlTemplate.Triggers> 260: </ControlTemplate>261: <Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}">
262: <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
263: <Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
264: <Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
265: <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
266: <Setter Property="BorderThickness" Value="1"/>
267: <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
268: <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
269: <Setter Property="Padding" Value="6,3,5,3"/>
270: <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
271: <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
272: <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
273: <Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
274: <Style.Triggers>275: <Trigger Property="IsEditable" Value="true">
276: <Setter Property="IsTabStop" Value="false"/>
277: <Setter Property="Padding" Value="2"/>
278: <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
279: </Trigger> 280: </Style.Triggers> 281: </Style> 282: </Window.Resources>搜尋關鍵字ComboBoxToggleButton可以找到下列文字
1: <ControlTemplate TargetType="{x:Type ToggleButton}">
2: <Border x:Name="templateRoot" BorderBrush="{StaticResource ComboBox.Static.Border}" BorderThickness="{TemplateBinding BorderThickness}" Background="{StaticResource ComboBox.Static.Background}" SnapsToDevicePixels="true">
3: <Border x:Name="splitBorder" BorderBrush="Transparent" BorderThickness="1" HorizontalAlignment="Right" Margin="0" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
4: <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.Static.Glyph}" HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center"/>
5: </Border> 6: </Border>接著從上面文字搜尋Background可以發現
Background="{StaticResource ComboBox.Static.Background}"
繼續搜尋關鍵字 StaticResource ComboBox.Static.Background
原本預設的顏色如下
1: <LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0">
2: <GradientStop Color="#FFF0F0F0" Offset="0.0"/>
3: <GradientStop Color="#FFE5E5E5" Offset="1.0"/>
4: </LinearGradientBrush>將上面這段文字遮蔽並貼上新的漸層定義
1: <!-- 2: <LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0,1" StartPoint="0,0">
3: <GradientStop Color="#FFF0F0F0" Offset="0.0"/>
4: <GradientStop Color="#FFE5E5E5" Offset="1.0"/>
5: </LinearGradientBrush> 6: /-->7: <LinearGradientBrush x:Key="ComboBox.Static.Background" EndPoint="0.5,1" StartPoint="0.5,0">
8: <GradientStop Color="Black" Offset="0"/>
9: <GradientStop Color="#FF25A861" Offset="1"/>
10: </LinearGradientBrush>置換後如下
另一個滑鼠移動到ComboBox上方時的屬性名稱ComboBox.MouseOver.Background
找到紅色關鍵字,修改Color數值
1: <LinearGradientBrush x:Key="ComboBox.MouseOver.Background" EndPoint="0,1" StartPoint="0,0">
2: <GradientStop Color="#FF11F4FC" Offset="0.0"/>
3: <GradientStop Color="#FF11ECFC" Offset="1.0"/>
4: </LinearGradientBrush>有關ComboBox下拉選單項目的背景顏色可以定義在<ComboBox.Resource>
1: <ComboBox Grid.Column="1" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" x:Name="comboxBox" Foreground="#FFF50A0A" FontSize="20" Style="{DynamicResource ComboBoxStyle1}">
2: <ComboBox.Resources> 3: <!-- color of ComboBoxItem -->4: <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="DarkSeaGreen" />
5: <!-- Mouse over color of ComboBoxItem -->6: <!--<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />-->
7: </ComboBox.Resources>8: <ComboBoxItem Content="Item1"/>
9: <ComboBoxItem Content="Item2"/>
10: <ComboBoxItem Content="Item3"/>
11: </ComboBox>參考資料
1. Changing The Background Color Of a ComboBox In WPF On Windows 8
全站熱搜




留言列表
