Applying Themes to an Application

The following topic details one method of applying a theme application-wide in Visual Studio. In this topic you'll add a class to your application that initializes a built-in theme. You'll then apply the theme to the MainPage of your application.

To apply the theme, complete the following steps:

1.   In Visual Studio, select File | New Project.

2.   In the New Project dialog box, select the language in the left pane and in the right-pane select Silverlight  Application. Enter a Name and Location for your project and click OK.

3.   In the New Silverlight Application dialog box, leave the default settings and click OK.

A new application will be created and should open with the MainPage.xaml file displayed in XAML view.

4.   In the Solution Explorer, right-click the project and choose Add Reference.

5.   In the Add Reference dialog box choose the C1.Silverlight.Theming and C1.Silverlight.Theming.RainierOrange assemblies and click OK.

6.   In the Solution Explorer, right-click the project and select Add | New Item.

7.   In the Add New Item dialog box, choose Class from the templates list, name the class "MyThemes", and click the Add button to create and a new class. The newly created MyThemes class will open.

8.   Add the following import statements to the top of the class:

      Visual Basic

      C#

9.   Add code to the class so it appears like the following:

      Visual Basic

      C#

10.  In the Solution Explorer, double-click the App.xaml.vb or App.xaml.cs file.

11.  Add the following import statement to the top of the file, where ProjectName is the name of your application:

      Visual Basic

      C#

12.  Add code to the Application_Startup event of the App.xaml.vb or App.xaml.cs file so it appears like the following:

      Visual Basic

      C#

Now any control you add to the MainPage.xaml file will automatically be themed.

13.  Return to the MainPage.xaml file and place the mouse cursor between the <Grid> and </Grid> tags in XAML view.

14.  In the Toolbox, double-click the C1DropDown icon to add the control to the project.

15.  Update the control's markup so it appears like the following:

<c1:C1DropDown Width="100" Height="30"></c1:C1DropDown>

What You’ve Accomplished

Run your project and observe that the C1DropDown control now appears in the RainierOrange theme. To change the theme chosen, now all you would need to do is change the theme in the MyThemes class.

For example, to change to the ExpressionDark theme:

1.   Add a reference to the C1.Theming.Silverlight.ExpressionDark.dll assembly.

2.   Open the MyThemes class in your project and add the following import statements to the top of the class:

      Visual Basic

      C#

3.   Update code in the class so it appears like the following:

      Visual Basic

      C#

Note that the above steps apply the theme to the MainPage.xaml file. To apply the theme to additional pages, you would need to add the following code to each page:

      Visual Basic

      C#

The theme will then be applied to the page. So, you only have to change one line of code to the class to change the theme, and you only have to add one line of code to each page to apply the theme.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.