36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
|
using System.Windows;
|
|||
|
|
|||
|
namespace DirectoryCreator
|
|||
|
{
|
|||
|
public static class ThemeManager
|
|||
|
{
|
|||
|
public static void SetTheme(bool isDarkTheme)
|
|||
|
{
|
|||
|
var app = Application.Current;
|
|||
|
var mergedDicts = app.Resources.MergedDictionaries;
|
|||
|
|
|||
|
// Ruta al tema oscuro
|
|||
|
var darkThemeUri = new Uri("Themes/DarkTheme.xaml", UriKind.Relative);
|
|||
|
|
|||
|
// Primero, removemos el tema oscuro si existe
|
|||
|
for (int i = mergedDicts.Count - 1; i >= 0; i--)
|
|||
|
{
|
|||
|
var currentDict = mergedDicts[i];
|
|||
|
if (currentDict.Source != null && currentDict.Source.Equals(darkThemeUri))
|
|||
|
{
|
|||
|
mergedDicts.RemoveAt(i);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Si se solicita el tema oscuro, lo agregamos
|
|||
|
if (isDarkTheme)
|
|||
|
{
|
|||
|
var darkTheme = new ResourceDictionary
|
|||
|
{
|
|||
|
Source = darkThemeUri
|
|||
|
};
|
|||
|
mergedDicts.Add(darkTheme);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|