@@ -32,13 +32,13 @@ public void SetLightDark(bool isDark)
32
32
33
33
source =
34
34
$ "pack://application:,,,/MahApps.Metro;component/Styles/Accents/{ ( isDark ? "BaseDark" : "BaseLight" ) } .xaml";
35
- var newMahAppsResourceDictionary = new ResourceDictionary ( ) { Source = new Uri ( source ) } ;
35
+ var newMahAppsResourceDictionary = new ResourceDictionary { Source = new Uri ( source ) } ;
36
36
37
37
Application . Current . Resources . MergedDictionaries . Remove ( existingMahAppsResourceDictionary ) ;
38
38
Application . Current . Resources . MergedDictionaries . Add ( newMahAppsResourceDictionary ) ;
39
39
}
40
40
41
- public void ReplacePrimaryColor ( Swatch swatch , bool mahapps = false )
41
+ public void ReplacePrimaryColor ( Swatch swatch )
42
42
{
43
43
if ( swatch == null ) throw new ArgumentNullException ( nameof ( swatch ) ) ;
44
44
@@ -60,24 +60,24 @@ public void ReplacePrimaryColor(Swatch swatch, bool mahapps = false)
60
60
ReplaceEntry ( "PrimaryHueDarkBrush" , new SolidColorBrush ( dark . Color ) ) ;
61
61
ReplaceEntry ( "PrimaryHueDarkForegroundBrush" , new SolidColorBrush ( dark . Foreground ) ) ;
62
62
63
- if ( mahapps )
64
- {
65
- ReplaceEntry ( "HighlightBrush" , new SolidColorBrush ( dark . Color ) ) ;
66
- ReplaceEntry ( "AccentColorBrush" , new SolidColorBrush ( list [ 5 ] . Color ) ) ;
67
- ReplaceEntry ( "AccentColorBrush2" , new SolidColorBrush ( list [ 4 ] . Color ) ) ;
68
- ReplaceEntry ( "AccentColorBrush3" , new SolidColorBrush ( list [ 3 ] . Color ) ) ;
69
- ReplaceEntry ( "AccentColorBrush4" , new SolidColorBrush ( list [ 2 ] . Color ) ) ;
70
- ReplaceEntry ( "WindowTitleColorBrush" , new SolidColorBrush ( dark . Color ) ) ;
71
- ReplaceEntry ( "AccentSelectedColorBrush" , new SolidColorBrush ( list [ 5 ] . Foreground ) ) ;
72
- ReplaceEntry ( "ProgressBrush" , new LinearGradientBrush ( dark . Color , list [ 3 ] . Color , 90.0 ) ) ;
73
- ReplaceEntry ( "CheckmarkFill" , new SolidColorBrush ( list [ 5 ] . Color ) ) ;
74
- ReplaceEntry ( "RightArrowFill" , new SolidColorBrush ( list [ 5 ] . Color ) ) ;
75
- ReplaceEntry ( "IdealForegroundColorBrush" , new SolidColorBrush ( list [ 5 ] . Foreground ) ) ;
76
- ReplaceEntry ( "IdealForegroundDisabledBrush" , new SolidColorBrush ( dark . Color ) { Opacity = .4 } ) ;
77
- }
63
+ // mahapps brushes
64
+ /*
65
+ ReplaceEntry("HighlightBrush", new SolidColorBrush(dark.Color));
66
+ ReplaceEntry("AccentColorBrush", new SolidColorBrush(list[5].Color));
67
+ ReplaceEntry("AccentColorBrush2", new SolidColorBrush(list[4].Color));
68
+ ReplaceEntry("AccentColorBrush3", new SolidColorBrush(list[3].Color));
69
+ ReplaceEntry("AccentColorBrush4", new SolidColorBrush(list[2].Color));
70
+ ReplaceEntry("WindowTitleColorBrush", new SolidColorBrush(dark.Color));
71
+ ReplaceEntry("AccentSelectedColorBrush", new SolidColorBrush(list[5].Foreground));
72
+ ReplaceEntry("ProgressBrush", new LinearGradientBrush(dark.Color, list[3].Color, 90.0));
73
+ ReplaceEntry("CheckmarkFill", new SolidColorBrush(list[5].Color));
74
+ ReplaceEntry("RightArrowFill", new SolidColorBrush(list[5].Color));
75
+ ReplaceEntry("IdealForegroundColorBrush", new SolidColorBrush(list[5].Foreground));
76
+ ReplaceEntry("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 });
77
+ */
78
78
}
79
79
80
- public void ReplacePrimaryColor ( string name , bool mahapps = false )
80
+ public void ReplacePrimaryColor ( string name )
81
81
{
82
82
if ( name == null ) throw new ArgumentNullException ( nameof ( name ) ) ;
83
83
@@ -87,7 +87,7 @@ public void ReplacePrimaryColor(string name, bool mahapps = false)
87
87
if ( swatch == null )
88
88
throw new ArgumentException ( $ "No such swatch '{ name } '", nameof ( name ) ) ;
89
89
90
- ReplacePrimaryColor ( swatch , mahapps ) ;
90
+ ReplacePrimaryColor ( swatch ) ;
91
91
}
92
92
93
93
public void ReplaceAccentColor ( Swatch swatch )
@@ -116,69 +116,37 @@ public void ReplaceAccentColor(string name)
116
116
117
117
ReplaceAccentColor ( swatch ) ;
118
118
}
119
- #region Pinvoke
120
- public struct PowerState
121
- {
122
- public ACLineStatus ACLineStatus ;
123
- public byte BatteryFlag ;
124
- public Byte BatteryLifePercent ;
125
- public Byte Reserved1 ;
126
- public Int32 BatteryLifeTime ;
127
- public Int32 BatteryFullLifeTime ;
128
- }
129
- [ DllImport ( "Kernel32" , EntryPoint = "GetSystemPowerStatus" ) ]
130
- private static extern bool GetSystemPowerStatusRef ( PowerState sps ) ;
131
-
132
- #endregion
133
- public static PowerState GetPowerState ( )
134
- {
135
- PowerState state = new PowerState ( ) ;
136
- if ( GetSystemPowerStatusRef ( state ) )
137
- return state ;
138
-
139
- throw new ApplicationException ( "Unable to get power state" ) ;
140
- }
141
- // Note: Underlying type of byte to match Win32 header
142
- public enum ACLineStatus : byte
143
- {
144
- Offline = 0 , Online = 1 , Unknown = 255
145
- }
146
- public static bool DisableAnimationOnBattery = true ;
119
+
147
120
/// <summary>
148
121
/// Replaces a certain entry anywhere in the parent dictionary and its merged dictionaries
149
122
/// </summary>
150
123
/// <param name="entryName">The entry to replace</param>
151
124
/// <param name="newValue">The new entry value</param>
152
125
/// <param name="parentDictionary">The root dictionary to start searching at. Null means using Application.Current.Resources</param>
153
- /// <returns>Weather the value was replaced (true) or not (false)</returns>
154
- private static bool ReplaceEntry ( object entryName , object newValue , ResourceDictionary parentDictionary = null , bool animate = true )
155
- {
156
- const int DURATION_MS = 500 ; //Change the value if needed
126
+ private static void ReplaceEntry ( object entryName , object newValue , ResourceDictionary parentDictionary = null )
127
+ {
157
128
if ( parentDictionary == null )
158
129
parentDictionary = Application . Current . Resources ;
159
130
160
131
if ( parentDictionary . Contains ( entryName ) )
161
132
{
162
- bool battery = GetPowerState ( ) . ACLineStatus == ACLineStatus . Online | ! DisableAnimationOnBattery ;
163
- if ( animate & parentDictionary [ entryName ] != null & battery & parentDictionary [ entryName ] as SolidColorBrush != null ) //Fade animation is enabled , type is solidcolorbrush and value is not null.
164
- {
165
- ColorAnimation animation = new ColorAnimation ( )
133
+ var brush = parentDictionary [ entryName ] as SolidColorBrush ;
134
+ if ( brush != null && ! brush . IsFrozen )
135
+ {
136
+ var animation = new ColorAnimation
166
137
{
167
- From = ( ( SolidColorBrush ) parentDictionary [ entryName ] ) . Color , //The old color
168
- To = ( ( SolidColorBrush ) newValue ) . Color , //The new color
169
- Duration = new Duration ( new TimeSpan ( 0 , 0 , 0 , 0 , DURATION_MS ) ) //Set the duration
138
+ From = ( ( SolidColorBrush ) parentDictionary [ entryName ] ) . Color ,
139
+ To = ( ( SolidColorBrush ) newValue ) . Color ,
140
+ Duration = new Duration ( TimeSpan . FromMilliseconds ( 300 ) )
170
141
} ;
171
- ( parentDictionary [ entryName ] as SolidColorBrush ) . BeginAnimation ( SolidColorBrush . ColorProperty , animation ) ; //Begin the animation
142
+ brush . BeginAnimation ( SolidColorBrush . ColorProperty , animation ) ;
172
143
}
173
144
else
174
145
parentDictionary [ entryName ] = newValue ; //Set value normally
175
- return true ;
176
146
}
147
+
177
148
foreach ( var dictionary in parentDictionary . MergedDictionaries )
178
- if ( ReplaceEntry ( entryName , newValue , dictionary ) )
179
- return true ;
180
-
181
- return false ;
149
+ ReplaceEntry ( entryName , newValue , dictionary ) ;
182
150
}
183
151
}
184
152
}
0 commit comments