// Register with the given SolidColorBrush to receive notifications whenever // the Color property changes. void RegisterColorChangeCallback(SolidColorBrush colorBrush) { if (colorBrush != _foregroundSolidColorBrush) { UnregisterColorPropertyChangedCallback(); _foregroundSolidColorBrush = colorBrush; if (colorBrush != null) { _colorPropertyChangedRegistration = _foregroundSolidColorBrush.RegisterPropertyChangedCallback( SolidColorBrush.ColorProperty, OnForegroundBrushColorChanged); } } }
internal static void ReInitAccentColorChanged() { if (_currentListenElement != null && _listenToken.HasValue) { _currentListenElement.UnregisterPropertyChangedCallback(SolidColorBrush.ColorProperty, _listenToken.Value); } if (_currentListenElement == null) { _currentListenElement = Window.Current.Content; if (_currentListenElement != null) { SolidColorBrush accentColorBrush = (SolidColorBrush)XamlReader.Load("<SolidColorBrush xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Color=\"{ThemeResource SystemAccentColor}\" />"); _listenToken = accentColorBrush.RegisterPropertyChangedCallback(SolidColorBrush.ColorProperty, (obj, dp) => { if (AccentColorChanged != null) { Color accentColor = (Color)obj.GetValue(dp); AccentColorChanged(obj, accentColor); } }); _currentListenElement.SetValue(AccentColorBrushProperty, accentColorBrush); } } }