Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit ead1af9

Browse files
committed
Clean up previous theme dictionary
1 parent f812ba7 commit ead1af9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/GitHub.VisualStudio.TestApp/ThemeControl.xaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace ThemedDialog.UI
1111
/// </summary>
1212
public partial class ThemeControl : UserControl
1313
{
14+
ResourceDictionary previousThemeResources;
15+
1416
public ThemeControl()
1517
{
1618
InitializeComponent();
@@ -24,7 +26,16 @@ void ThemeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
2426
{
2527
if (TryFindResource($"Themes/{theme}") is ResourceDictionary themeResources)
2628
{
27-
Application.Current.Resources.MergedDictionaries.Add(themeResources);
29+
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
30+
mergedDictionaries.Add(themeResources);
31+
32+
if(previousThemeResources != null)
33+
{
34+
mergedDictionaries.Remove(previousThemeResources);
35+
}
36+
37+
previousThemeResources = themeResources;
38+
2839
FireThemeChangedEvent();
2940
}
3041
}

0 commit comments

Comments
 (0)