You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.7 KiB
96 lines
2.7 KiB
namespace ex_CustomThemes;
|
|
using System.Linq;
|
|
|
|
public partial class MainPage : ContentPage
|
|
{
|
|
public MainPage()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Application.Current.RequestedThemeChanged += (s, a) =>
|
|
// {
|
|
// if(Preferences.Default.Get<string>("Theme", null) != "System")
|
|
// {
|
|
// return;
|
|
// }
|
|
// ResourceDictionary chosenTheme = Application.Current.RequestedTheme switch
|
|
// {
|
|
// AppTheme.Light => new LightTheme(),
|
|
// AppTheme.Dark => new DarkTheme(),
|
|
// _ => new LightTheme()
|
|
// };
|
|
|
|
// ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
|
|
// if (mergedDictionaries != null)
|
|
// {
|
|
// foreach(var dico in mergedDictionaries.Where(d => d is ICustomThemes).ToList())
|
|
// {
|
|
// mergedDictionaries.Remove(dico);
|
|
// }
|
|
// mergedDictionaries.Add(chosenTheme);
|
|
// }
|
|
// };
|
|
|
|
}
|
|
|
|
void picker_SelectedIndexChanged(object source, EventArgs args)
|
|
{
|
|
string? chosenThemeString = picker.SelectedItem as string;
|
|
|
|
ResourceDictionary chosenTheme = chosenThemeString switch
|
|
{
|
|
"Dark" => new DarkTheme(),
|
|
"Light" => new LightTheme(),
|
|
"Color Blind" => new ColorBlindTheme(),
|
|
_ => new LightTheme()
|
|
};
|
|
|
|
ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
|
|
if (mergedDictionaries != null)
|
|
{
|
|
foreach(var dico in mergedDictionaries.Where(d => d is ICustomTheme).ToList())
|
|
{
|
|
mergedDictionaries.Remove(dico);
|
|
}
|
|
mergedDictionaries.Add(chosenTheme);
|
|
}
|
|
|
|
// ResourceDictionary chosenTheme;
|
|
// switch(chosenThemeString)
|
|
// {
|
|
// case "Dark":
|
|
// chosenTheme = new DarkTheme();
|
|
// Preferences.Default.Set("Theme", "Dark");
|
|
// break;
|
|
// case "Light":
|
|
// chosenTheme = new LightTheme();
|
|
// Preferences.Default.Set("Theme", "Light");
|
|
// break;
|
|
// case "Color Blind":
|
|
// chosenTheme = new ColorBlindTheme();
|
|
// Preferences.Default.Set("Theme", "Color Blind");
|
|
// break;
|
|
// default:
|
|
// Preferences.Default.Set("Theme", "System");
|
|
// chosenTheme = Application.Current.RequestedTheme switch
|
|
// {
|
|
// AppTheme.Light => new LightTheme(),
|
|
// AppTheme.Dark => new DarkTheme(),
|
|
// _ => new LightTheme()
|
|
// };
|
|
// break;
|
|
// };
|
|
|
|
// ICollection<ResourceDictionary> mergedDictionaries = Application.Current.Resources.MergedDictionaries;
|
|
// if (mergedDictionaries != null)
|
|
// {
|
|
// foreach(var dico in mergedDictionaries.Where(d => d is ICustomThemes).ToList())
|
|
// {
|
|
// mergedDictionaries.Remove(dico);
|
|
// }
|
|
// mergedDictionaries.Add(chosenTheme);
|
|
// }
|
|
}
|
|
}
|
|
|