Theming > 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:
Visual Basic |
Copy Code
|
---|---|
Imports C1.WPF.Theming Imports C1.WPF.Theming.C1Blue |
C# |
Copy Code
|
---|---|
using C1.WPF.Theming; using C1.WPF.Theming.C1Blue; |
Visual Basic |
Copy Code
|
---|---|
Public Class MyThemes Private Shared _myTheme As C1Theme = NothingPublic Shared ReadOnly Property MyTheme() As C1Theme Get If _myTheme Is Nothing Then_myTheme = New C1ThemeRainierOrange()End If Return _myThemeEnd GetEnd Property End Class |
C# |
Copy Code
|
---|---|
public class MyThemes{private static C1Theme _myTheme = null;public static C1Theme MyTheme{get{if (_myTheme == null)_myTheme = new C1ThemeRainierOrange();return _myTheme;}}} |
Visual Basic |
Copy Code
|
---|---|
Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.StartupDim MyMainPage As New MainPage()Dim themes As New MyThemesthemes.MyTheme.Apply(MyMainPage)Me.RootVisual = MyMainPageEnd Sub |
C# |
Copy Code
|
---|---|
private void Application_Startup(object sender, StartupEventArgs e){MainPage MyMainPage = new MainPage();MyThemes.MyTheme.Apply(MyMainPage);this.RootVisual = MyMainPage;} |
Now any control you add to the MainPage.xaml file will automatically be themed.
XAML |
Copy Code
|
---|---|
<c1:C1DropDown Width="100" Height="30"></c1:C1DropDown> |
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:
Visual Basic |
Copy Code
|
---|---|
Imports C1.WPF.Theming.ExpressionDark
|
C# |
Copy Code
|
---|---|
using C1.WPF.Theming.ExpressionDark;
|
Visual Basic |
Copy Code
|
---|---|
Public Class MyThemesPrivate _myTheme As C1Theme = NothingPublic ReadOnly Property MyTheme() As C1ThemeGetIf _myTheme Is Nothing Then_myTheme = New C1ThemeExpressionDark()End IfReturn _myThemeEnd GetEnd PropertyEnd Class |
C# |
Copy Code
|
---|---|
public class MyThemes{private static C1Theme _myTheme = null;public static C1Theme MyTheme{get{if (_myTheme == null)_myTheme = new C1ThemeExpressionDark();return _myTheme;}}} |
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 |
Copy Code
|
---|---|
Dim themes As New MyThemes themes.MyTheme.Apply(MyMainPage) |
C# |
Copy Code
|
---|---|
MyThemes themes = new MyThemes();
themes.MyTheme.Apply(MyMainPage);
|