Miscellaneous Styling Tips

Here are a few miscellaneous tips that you may find useful when designing your style resources.

Defining Constants in XAML

In instances where you want to maintain a set of constant values that can be used by multiple controls or style resources but that can be maintained in a single location, you can simply define those values as resources. For example, here we are defining a color constant that we can use:

<SolidColorBrush x:Key="BackgroundColorResource" Color="LemonChiffon "/>

You can then assign this resource directly to a control by using the StaticResource markup extension:

<TextBox Background="{StaticResource BackgroundColorResource}" />

Or you can use it in a style resource definition:

<Style x:Key="UserFieldsStyleBase" ...

Get Pro Business Applications with Silverlight 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.