40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Windows;
|
|
|
|
namespace DirectoryCreator
|
|
{
|
|
public static class ThemeManager
|
|
{
|
|
private static readonly Uri DarkThemeUri = new Uri("/Themes/DarkTheme.xaml", UriKind.Relative);
|
|
private static readonly Uri LightThemeUri = new Uri("/Themes/LightTheme.xaml", UriKind.Relative);
|
|
|
|
public static void SetTheme(bool isDarkTheme)
|
|
{
|
|
var app = Application.Current;
|
|
if (app == null) return;
|
|
|
|
var mergedDicts = app.Resources.MergedDictionaries;
|
|
|
|
// Buscar y eliminar los temas existentes
|
|
ResourceDictionary themeToRemove = null;
|
|
foreach (ResourceDictionary dict in mergedDicts)
|
|
{
|
|
if (dict.Source != null && (dict.Source.OriginalString.Contains("LightTheme") || dict.Source.OriginalString.Contains("DarkTheme")))
|
|
{
|
|
themeToRemove = dict;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (themeToRemove != null)
|
|
{
|
|
mergedDicts.Remove(themeToRemove);
|
|
}
|
|
|
|
// Agregar el nuevo tema
|
|
mergedDicts.Add(new ResourceDictionary
|
|
{
|
|
Source = isDarkTheme ? DarkThemeUri : LightThemeUri
|
|
});
|
|
}
|
|
}
|
|
} |