C# Online.NET Visual C# Developer Center
Search

WPF Styles and Control Templates—Named Styles

Visual C# Tutorials
.NET Framework Tutorials

WPF Styles and Control Templates

© 2005 O'Reilly Media

WPF Named Styles

By hoisting the same inline style into a resource, we can award it a name and use it by name in our button instances, as shown in Example 5-5.

Example 5-5. Setting a named style

<!-- Window1.xaml -->
<Window ...>
  <Window.Resources>
    <Style x:Key="CellTextStyle">
      <Setter Property="Control.FontSize" Value="32" />
      <Setter Property="Control.FontWeight" Value="Bold" />
    </Style>
  </Window.Resources>
  ...
  <Button Style="{StaticResource CellTextStyle}" ... 
    x:Name="cell00" />
  ...
</Window>

In Example 5-5, we’ve used the Control prefix on our properties instead of the Button prefix to allow the style to be used more broadly, as we’ll soon see.


Previous_Page_.gif Next_Page_.gif