5.2. 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 seti.e., FontSize and FontWeightboth
with the Button prefix to indicate the class that contains the
property. Properties suitable for styling are dependency properties, which are
described in Chapter 9.
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.
 |