Applying Themes to an Application
In This Topic
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:
- In Visual Studio, select File | New Project.
- In the New Project dialog box, select the language in the left pane and in the right-pane select WPF Application. Enter a Name and Location for your project and click OK.
- In the New WPF 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.
- In the Solution Explorer, right-click the project and choose Add Reference.
- In the Add Reference dialog box choose the C1.WPF.Theming and C1.WPF.Theming.C1Blue assemblies and click OK.
- In the Solution Explorer, right-click the project and select Add | New Item.
- 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.
- Add the following import statements to the top of the class:
- Add code to the class so it appears like the following:
- In the Solution Explorer, double-click the App.xaml.vb or App.xaml.cs file.
- Add the following import statement to the top of the file, where ProjectName is the name of your application:
- Add code to the Application_Startup event of the App.xaml.vb or App.xaml.cs file so it appears like the following:
Now any control you add to the MainPage.xaml file will automatically be themed.
- Return to the MainPage.xaml file and place the mouse cursor between the <Grid> and </Grid> tags in XAML view.
- In the Toolbox, double-click the C1DropDown icon to add the control to the project.
- Update the control's markup so it appears like the following:
XAML |
Copy Code
|
<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:
- Add a reference to the C1.Theming.WPF.ExpressionDark.dll assembly.
- Open the MyThemes class in your project and add the following import statements to the top of the class:
- Update code in the class so it appears like the following:
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:
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.
See Also