using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using TodoDetails.Resources.Styles; using TodoDetails.Resources.Themes; namespace TodoDetails.ViewModel { public class SettingsViewModel { private Dictionary defaultThemes = new() { { "Light", new Light() }, { "Dark", new Dark() }, { "Earth", new Earth() }, { "Pink", new Pink() } }; public SettingsViewModel() { Themes = defaultThemes.Select(x => x.Key).ToList(); } public List Themes { get; set; } public void LoadNewTheme(string themeName) { if (!MainThread.IsMainThread) { MainThread.BeginInvokeOnMainThread(() => LoadNewTheme(themeName)); return; } ResourceDictionary dictionary = defaultThemes[themeName]; if (dictionary != null) { Application.Current.Resources.MergedDictionaries.Clear(); Application.Current.Resources.MergedDictionaries.Add(new ThemeStyles()); Application.Current.Resources.MergedDictionaries.Add(dictionary); } } } }