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.Silverlight.Theming Imports C1.Silverlight.Theming.RainierOrange |
C# |
Copy Code
|
---|---|
using C1.Silverlight.Theming; using C1.Silverlight.RainierOrange; |
Visual Basic |
Copy Code
|
---|---|
Public Class MyThemes Private _myTheme As C1Theme = Nothing Public ReadOnly Property MyTheme() As C1Theme Get If _myTheme Is Nothing Then _myTheme = New C1ThemeRainierOrange() End If Return _myTheme End Get End 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
|
---|---|
Imports ProjectName
|
C# |
Copy Code
|
---|---|
using ProjectName;
|
Visual Basic |
Copy Code
|
---|---|
Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup Dim MyMainPage As New MainPage() Dim themes As New MyThemes themes.MyTheme.Apply(MyMainPage) Me.RootVisual = MyMainPage End 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.
<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:
Visual Basic |
Copy Code
|
---|---|
Imports C1.Silverlight.Theming.ExpressionDark
|
C# |
Copy Code
|
---|---|
using C1.Silverlight.Theming.ExpressionDark;
|
Visual Basic |
Copy Code
|
---|---|
Public Class MyThemes Private _myTheme As C1Theme = Nothing Public ReadOnly Property MyTheme() As C1Theme Get If _myTheme Is Nothing Then _myTheme = New C1ThemeExpressionDark() End If Return _myTheme End Get End Property End 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.MyTheme.Apply(LayoutRoot); |
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.