#143 – Dependency Property Value Sources: #9 – Theme Style

The ninth source in the list of sources for the base value of a dependency property is a theme style.  A property gets its base value from a theme style if the value comes from a setter in the default style for a control. Every control that ships with WPF has a default style that dictates its appearance, also known as a theme style.

If we look at the default style for a ComboBox control, we see that the default style sets the Background property of the ComboBox:

		<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}">
			<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
			<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>

So, by default, the source of this property is DefaultStyle (theme style).

If we then set the IsEditable property to true, a trigger in the default style fires and the source becomes DefaultStyleTrigger (theme style trigger).

#142 – Dependency Property Value Sources: #8 – Theme Style Triggers

The eighth source in the list of sources for the base value of a dependency property is a theme style trigger.  A theme style trigger is a trigger defined in the default style for a control.  Every control that ships with WPF has a default style that dictates its appearance, also known as a theme style.

As an example, notice that when you set the IsEditable property of a ComboBox to true, it’s appearance changes.

IsEditable false:  

IsEditable true:  

The change in appearance is caused by a trigger in the default style.  If you right-click on a ComboBox in Blend and pick Edit a Template | Edit a Copy, you can see the default style for a ComboBox, including the following trigger on IsEditable.

				<Trigger Property="IsEditable" Value="true">
					<Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
					<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
					<Setter Property="IsTabStop" Value="false"/>
					<Setter Property="Padding" Value="3"/>
					<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
				</Trigger>