This topic details one method of applying a theme application-wide in Visual Studio. We add a class to our application that initializes a built-in theme, then apply the theme to the MainPage of our 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; } |
HTML |
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. Now you can 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, 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 is applied to the page. So, you only need change one line of code to the class to change the theme, and you only need add one line of code to each page to apply the theme.