forked from github/VisualStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThemeControl.xaml.cs
More file actions
57 lines (50 loc) · 1.9 KB
/
Copy pathThemeControl.xaml.cs
File metadata and controls
57 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using Microsoft;
namespace ThemedDialog.UI
{
/// <summary>
/// Interaction logic for ThemeControl.xaml
/// </summary>
public partial class ThemeControl : UserControl
{
ResourceDictionary previousThemeResources;
public ThemeControl()
{
InitializeComponent();
}
void ThemeListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ThemeListBox.SelectedItem is Label label)
{
if (label.Content is string theme)
{
if (TryFindResource($"Themes/{theme}") is ResourceDictionary themeResources)
{
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
mergedDictionaries.Add(themeResources);
if(previousThemeResources != null)
{
mergedDictionaries.Remove(previousThemeResources);
}
previousThemeResources = themeResources;
FireThemeChangedEvent();
}
}
}
}
static void FireThemeChangedEvent()
{
var type = Type.GetType("Microsoft.VisualStudio.PlatformUI.VSColorTheme, Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
Assumes.NotNull(type);
var themeChangedStorage = type.GetField("ThemeChangedStorage", BindingFlags.Static | BindingFlags.NonPublic);
Assumes.NotNull(themeChangedStorage);
if (themeChangedStorage.GetValue(null) is Delegate method)
{
method.DynamicInvoke(new object[] { null });
}
}
}
}