47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
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<string, ResourceDictionary> 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<string> 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);
|
|
}
|
|
}
|
|
}
|
|
}
|