WPF Dialog window not getting theme keys for styles
I've got some keys in a resource that aren't being passed to the resources of the child windows. I'm wondering if this is due to my code below. The resource with the key is being added again after the resources are cleared. The window is being newly created each time. This is done to switch themes. There's more code than this, but this is the gist. The theme switching works fine for the main window, but not for the child windows. Why are my keys not being passed to the child windows? When the window tries to open it crashes.
public static void SwitchTheme(string themeName, bool isDark)
{
System.Windows.Application.Current.Resources.MergedDictionaries.Clear();
if (themeName == "Fluent")
{
if (isDark)
{
FluentPalette.LoadPreset(FluentPalette.ColorVariation.Dark);
}
else
{
FluentPalette.LoadPreset(FluentPalette.ColorVariation.Light);
}
}
if (themeName == "Crystal")
{
if (isDark)
{
CrystalPalette.LoadPreset(CrystalPalette.ColorVariation.Dark);
}
else
{
CrystalPalette.LoadPreset(CrystalPalette.ColorVariation.Light);
}
}
System.Windows.Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
{
Source = new Uri("/IropsAnalyzer.UI.Wpf;component/Styles/WindowStyles.xaml", UriKind.RelativeOrAbsolute)
});
}