|
1 |
| -/************************************************************************ |
| 1 | +/************************************************************************ |
2 | 2 | AvalonDock
|
3 | 3 |
|
4 | 4 | Copyright (C) 2007-2013 Xceed Software Inc.
|
@@ -42,6 +42,9 @@ namespace AvalonDock
|
42 | 42 | public class DockingManager : Control, IOverlayWindowHost//, ILogicalChildrenContainer
|
43 | 43 | {
|
44 | 44 | #region fields
|
| 45 | + // ShortCut to current AvalonDock theme if OnThemeChanged() is invoked with DictionaryTheme instance |
| 46 | + // in e.OldValue and e.NewValue of the passed event |
| 47 | + private ResourceDictionary currentThemeResourceDictionary; |
45 | 48 |
|
46 | 49 | private AutoHideWindowManager _autoHideWindowManager;
|
47 | 50 | private FrameworkElement _autohideArea;
|
@@ -1029,24 +1032,41 @@ protected virtual void OnThemeChanged(DependencyPropertyChangedEventArgs e)
|
1029 | 1032 | {
|
1030 | 1033 | var oldTheme = e.OldValue as Theme;
|
1031 | 1034 | var resources = Resources;
|
1032 |
| - if (oldTheme != null) |
| 1035 | + if (oldTheme != null) // remove old theme from resource dictionary if present |
1033 | 1036 | {
|
1034 |
| - var resourceDictionaryToRemove = |
1035 |
| - resources.MergedDictionaries.FirstOrDefault(r => r.Source == oldTheme.GetResourceUri()); |
1036 |
| - if (resourceDictionaryToRemove != null) |
1037 |
| - resources.MergedDictionaries.Remove( |
1038 |
| - resourceDictionaryToRemove); |
| 1037 | + if (oldTheme is DictionaryTheme) // We are using AvalonDock's own DictionaryTheme class |
| 1038 | + { |
| 1039 | + if (currentThemeResourceDictionary != null) |
| 1040 | + { |
| 1041 | + resources.MergedDictionaries.Remove(currentThemeResourceDictionary); |
| 1042 | + currentThemeResourceDictionary = null; |
| 1043 | + } |
| 1044 | + } |
| 1045 | + else // We are using standard ResourceDictionaries |
| 1046 | + { // Lockup the old theme and remove it from resource dictionary |
| 1047 | + var resourceDictionaryToRemove = |
| 1048 | + resources.MergedDictionaries.FirstOrDefault(r => r.Source == oldTheme.GetResourceUri()); |
| 1049 | + if (resourceDictionaryToRemove != null) |
| 1050 | + resources.MergedDictionaries.Remove( |
| 1051 | + resourceDictionaryToRemove); |
| 1052 | + } |
1039 | 1053 | }
|
1040 | 1054 |
|
1041 |
| - if (e.NewValue as Theme != null) |
| 1055 | + if (e.NewValue as Theme != null) // Add new theme into resource dictionary if present |
1042 | 1056 | {
|
1043 |
| - resources.MergedDictionaries.Add(new ResourceDictionary { Source = (e.NewValue as Theme).GetResourceUri() }); |
| 1057 | + if (e.NewValue as Theme is DictionaryTheme theme) |
| 1058 | + { |
| 1059 | + currentThemeResourceDictionary = theme.ThemeResourceDictionary; |
| 1060 | + resources.MergedDictionaries.Add(currentThemeResourceDictionary); |
| 1061 | + } |
| 1062 | + else // We are using standard ResourceDictionaries -> Add new theme resource |
| 1063 | + resources.MergedDictionaries.Add(new ResourceDictionary { Source = (e.NewValue as Theme).GetResourceUri() }); |
1044 | 1064 | }
|
1045 | 1065 |
|
1046 |
| - foreach (var fwc in _fwList) |
| 1066 | + foreach (var fwc in _fwList) // Update theme resources in floating window controls |
1047 | 1067 | fwc.UpdateThemeResources(oldTheme);
|
1048 | 1068 |
|
1049 |
| - _navigatorWindow?.UpdateThemeResources(); |
| 1069 | + _navigatorWindow?.UpdateThemeResources(); // Update theme resources in related AvalonDock controls |
1050 | 1070 | _overlayWindow?.UpdateThemeResources();
|
1051 | 1071 | }
|
1052 | 1072 |
|
|
0 commit comments