Skip to content

Instantly share code, notes, and snippets.

@LanceMcCarthy
Created February 19, 2018 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LanceMcCarthy/67c88a7f9945100f0cb016857dbc3ddd to your computer and use it in GitHub Desktop.
Save LanceMcCarthy/67c88a7f9945100f0cb016857dbc3ddd to your computer and use it in GitHub Desktop.
Helper class to change theme resources at runtime
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