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

Commit 407b224

Browse files
committed
Fire VSColorTheme.ThemeChanged event when changing theme
1 parent c48f494 commit 407b224

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Reflection;
23
using System.Windows;
34
using System.Windows.Controls;
5+
using Microsoft;
46

57
namespace ThemedDialog.UI
68
{
@@ -23,9 +25,22 @@ void ThemeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
2325
if (TryFindResource($"Themes/{theme}") is ResourceDictionary themeResources)
2426
{
2527
Application.Current.Resources.MergedDictionaries.Add(themeResources);
28+
FireThemeChangedEvent();
2629
}
2730
}
2831
}
2932
}
33+
34+
static void FireThemeChangedEvent()
35+
{
36+
var type = Type.GetType("Microsoft.VisualStudio.PlatformUI.VSColorTheme, Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
37+
Assumes.NotNull(type);
38+
var themeChangedStorage = type.GetField("ThemeChangedStorage", BindingFlags.Static | BindingFlags.NonPublic);
39+
Assumes.NotNull(themeChangedStorage);
40+
if (themeChangedStorage.GetValue(null) is Delegate method)
41+
{
42+
method.DynamicInvoke(new object[] { null });
43+
}
44+
}
3045
}
3146
}

0 commit comments

Comments
 (0)