Theming

Theming (sometimes also known as skinning) is essentially the process of either styling or retemplating control types to customize their appearance by overriding their default styles or control templates. Themes are generally designed as a way of maintaining the look of the controls in the application in a single location in your project, ensuring consistency across your application and simplifying maintenance. However, they are also particularly useful when creating packaged software that should make use of corporate colors and display the customer's branding.

The styles and control templates from a theme are automatically applied to their corresponding control instances wherever they may appear throughout the application.

Your application may also define a number of themes that the user can choose from. To do so, define each theme in a separate resource dictionary, and merge the selected theme file with the application's resources at runtime to apply it.

Creating a Custom Theme

You can create your own theme file by creating a resource dictionary, placing all of your style resources in it, and merging it with the application's resources, as detailed earlier in this chapter. You can also define this resource file in a separate assembly, which enables you to share in between projects.

You can define a new control template in a style resource to completely change the look of the target control type. Assign it to the control's Template property defined in the style, like so:

<Style TargetType="Button">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <!-- Control template goes here -->
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

If you make this style resource an implicit style, all controls of the specified target type for the style will automatically have the control template applied, thus resulting in a theme-like behavior.

Using Silverlight Toolkit Themes

The Silverlight Toolkit includes an array of predefined themes that you may like to use in your project to retemplate the standard Silverlight controls and the Silverlight Toolkit controls, providing a new distinct look to your application. You can use these as they are or modify them to suit your own tastes. More information can be found on the Silverlight Toolkit's CodePlex site at http://silverlight.codeplex.com.

Installing Silverlight Navigation and Business Application Themed Project Templates

Microsoft has started to release project templates that both restructure the visual layout of the application and retheme all the core Silverlight and Silverlight Toolkit controls—in other words, defining new control templates for all these controls.

You can download and install these from the Visual Studio Online Gallery, via Visual Studio's Extension Manager. From the Online Gallery, navigate to the Templates images Silverlight category to find them. At the time of this writing, only the themes for the Silverlight Navigation Application project types are available for installing as project templates, but you can download Silverlight Business Application projects implementing these themes at www.microsoft.com/downloads/details.aspx?FamilyID=e9da0eb8-f31b-4490-85b8-92c2f807df9e&displaylang=en.

You will find a project template for each theme you install in the Silverlight category of Visual Studio's New Project dialog, which you can then use when creating a project.

New themes will be released over time, and at the time of this writing, the released themes include the following:

  • Accent Color
  • Cosmopolitan
  • Windows 7
  • JetPack
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset