Extending Styles

In addition to the abilities to reuse and override existing styles, you can also extend a style, adding new properties or overriding existing ones (see Example 8-11).

Example 8-11. Extending a style

<Style x:Key="CellTextStyle"> <Setter Property="Control.FontSize" Value="32pt" /> <Setter Property="Control.FontWeight" Value="Bold" /> </Style>

<Style x:Key="StatusTextStyle" BasedOn="{StaticResource CellTextStyle}">

<Setter Property="TextBlock.FontWeight" Value="Normal" /> <Setter Property="TextBlock.Foreground" Value="White" /> <Setter Property="TextBlock.HorizontalAlignment" Value="Center" /> </Style>

The BasedOn style attribute is used to designate the style being extended. In Example 8-11, the StatusTextStyle style gets all of the CellTextStyle property setters, overrides the FontWeight, and adds setters for Foreground and HorizontalAlignment. Our current use of styles causes our tic-tac-toe game to look like Figure 8-4.

Figure 8-4. A tic-tac-toe game with more style

Our application so far is looking pretty good, but we can do better.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment