Created
February 19, 2018 20:00
-
-
Save LanceMcCarthy/67c88a7f9945100f0cb016857dbc3ddd to your computer and use it in GitHub Desktop.
Helper class to change theme resources at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Telerik.XamarinForms.Common; | |
using Xamarin.Forms; | |
namespace YourAwesomeApp.Helpers | |
{ | |
public static class ThemeHelper | |
{ | |
public static void ChangeTheme(string themeName) | |
{ | |
if(Application.Current.Resources != null) | |
Application.Current.Resources.Clear(); | |
var resourceDictionary = new RadResourceDictionary(); | |
// Select your chose theme's colors | |
if (themeName == "Default") | |
{ | |
// Don't add a separate resource dictionary to use the Default theme | |
} | |
else if (themeName == "TelerikBlue") | |
{ | |
// This is the BlueTheme delivered with UI for Xamarin | |
resourceDictionary.MergedDictionaries.Add(new BlueResources()); | |
} | |
else if (themeName == "Custom") | |
{ | |
// This is the custom ResourceDictionary you've created | |
resourceDictionary.MergedDictionaries.Add(new CustomTheme()); | |
} | |
// Merge the rest of the resources | |
resourceDictionary.MergedDictionaries.Add(new Telerik.XamarinForms.Input.TelerikThemeStyles()); | |
resourceDictionary.MergedDictionaries.Add(new Telerik.XamarinForms.Primitives.TelerikThemeStyles()); | |
resourceDictionary.MergedDictionaries.Add(new Telerik.XamarinForms.Chart.TelerikThemeStyles()); | |
resourceDictionary.MergedDictionaries.Add(new Telerik.XamarinForms.DataControls.TelerikThemeStyles()); | |
resourceDictionary.MergedDictionaries.Add(new Telerik.XamarinForms.DataGrid.TelerikThemeStyles()); | |
Application.Current.Resources = resourceDictionary; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment