#138 – Dependency Property Value Sources: #4 – Implicit Style
November 27, 2010 2 Comments
The fourth source in the list of sources for the base value of a dependency property is an implicit style. This rule applies only to the Style dependency property.
The Style property obtains its value implicitly when a style is applied to all elements whose type matches the specified TargetType of the style.
Since an explicit style is treated as a local value, the resulting precedence list for the Style property, highest to lowest, is:
- Explicit style (local value)
- Implicit style
- Default value
In the example below, we use an implicit style to set the style of two different Button elements.
<Window.Resources> <Style TargetType="Button"> <Setter Property="Control.FontStyle" Value="Italic"/> </Style> </Window.Resources> <StackPanel> <Button Content="Click Me" Height="23" Width="125" /> <Button Content="Or Me" Height="23" Width="125" /> </StackPanel>