WPF Styles and Control Templates—Inline Styles
| Visual C# Tutorials |
| .NET Framework Tutorials |
| © 2005 O'Reilly Media |
WPF Inline Styles
Each "style-able" element in WPF has a Style property, which can be set inline using
standard XAML property-element syntax (discussed in Chapter 1), as in
Example 5-4.
Example 5-4. Setting an inline style
<Button ... x:Name="cell00" /> <Button.Style> <Style> <Setter Property="Button.FontSize" Value="32" /> <Setter Property="Button.FontWeight" Value="Bold" /> </Style> </Button.Style> </Button>
Because we want to bundle two property values into our style, we have a Style element
with two Setter sub-elements, one for each property we want to set—i.e.,
FontSize and FontWeight—both with the Button prefix to indicate the class that contains
the property. Properties suitable for styling are dependency properties.
Due to the extra style syntax and because inline styles can’t be shared across elements, inline styles actually involve more typing than just setting the properties. For this reason, inline styles aren’t used nearly as often as named styles.
|

