THEMES AND RESOURCES

You can easily restyle applications and controls in the Silverlight framework. (This process is also known as skinning, or theming.) Blend makes this restyling even easier, as explained in this section.

Managing Resources

In Silverlight, a Resource is simply an object that's declared in a ResourceDictionary in XAML. Because it's in the ResourceDictionary, it's made available to all the children of the item that owns that ResourceDictionary. This means that if you declare a resource in the ResourceDictionary of a Page, you can use that resource from anywhere in that page. In XAML, you access the value of a resource with the syntax {StaticResource keyName}, where keyName is the key name chosen for the resource (with the syntax x:Key=“keyName”).

Using resources is a perfect way to reuse objects and values in Silverlight. You can specify something once, reference it from multiple places, and when you update the original resource in Blend or Visual Studio all the references will reflect these changes.

Making Your Own Resources

Blend makes it easy to work with resources. Most property values can be extracted into a resource: In the property's Advanced Options menu (the peg, discussed earlier in this chapter, in the sidebar “Property Pegs”), there's an option called Convert to New Resource. Invoking this brings up a dialog from which you can pick a name for the resource and choose where to keep it. This dialog lets you keep the resource in a number of places:

  • Application ...

Get Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® 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.