I am trying to detect changes in the Application.Resources Resource dictionary, so I can automatically change the Titlebar to the Accent Colour when it updates. All of the XAML controls and elements change automatically, and when setting a solid colour brush to the address of the DSDFS brush, its internal value changes.
This is the code I have tried to use to detect the change:
public static DependencyProperty accent = DependencyProperty.Register("DictChange", typeof(ResourceDictionary), typeof(Shell), new PropertyMetadata(Application.Current.Resources, new PropertyChangedCallback(accent_PropertyChanged)));
public ResourceDictionary DictChange
{
get { return (ResourceDictionary)GetValue(accent); }
set { SetValue(accent, value); }
}
private static void accent_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
_app.SetTitlebar();
}
I'm assuming its wrong though, or I'm not sure if that is the right thing to do to detect changes. There was a previous iteration where I used Application.Current.Resources["SystemControlBackgroundAccentBrush"] as SolidColorBrush
and tried to detect its property, but that didn't work either.
What am I doing wrong? Please help :)
It might not be wrong, but it's probably not the best solution available.
In WinRT XAML, we have this new
ThemeResource
that updates the resources automatically. The tricky bit is to find a way to bind theApplicationView.GetForCurrentView().TitleBar.BackgroundColor
toSystemControlBackgroundAccentBrush
.In my answer to this question, I created a
Behavior
that attaches a customTitleBar
to the page. If you modify theBackground
property to something like this -Now run the app and you will see the background color gets updated when you change the
accent color
of the system, as shown in the picture below -Basically in your case, you just need to create a similar (& simpler?)
Behavior
that acts like a bridge to link theBackgroundColor
of theTitleBar
to theSystemControlBackgroundAccentBrush
, viaThemeResource
binding.Hope this helps!
You cannot detect the key-value changes in the Resource Dictionary by registering a DependencyProperty because the ResourceDictionay is not an ObservableCollection Class.
There are no build-in support to detect the key-value changes in a Resource Dictionary.
As a workaround, you can consider create an internal observable collection to detect the changes.