C# Detect Accent Colour Changes WinRT XAML

眉间皱痕 提交于 2019-12-04 14:50:59
Justin XL

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 the ApplicationView.GetForCurrentView().TitleBar.BackgroundColor to SystemControlBackgroundAccentBrush.

In my answer to this question, I created a Behavior that attaches a custom TitleBar to the page. If you modify the Background property to something like this -

<local:FullScreenModeTitleBarBehavior Background="{ThemeResource SystemControlBackgroundAccentBrush}" />

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 the BackgroundColor of the TitleBar to the SystemControlBackgroundAccentBrush, via ThemeResource binding.

Hope this helps!

I'm assuming its wrong though, or I'm not sure if that is the right thing to do to detect changes.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!