C#检测口音颜色变化的WinRT XAML [英] C# Detect Accent Colour Changes WinRT XAML
问题描述
我试图来检测Application.Resources资源词典的变化,这样我就可以在标题栏自动改变为雅绅特色时更新。所有XAML控件和元素的自动变化,和纯色画笔设置为 DSDFS 的刷子,其内在价值的变化。
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();
}
我虽然承担了错,还是我不知道如果这就是做检测更改正确的事情。有一个前一次迭代中,我用 Application.Current.Resources [SystemControlBackgroundAccentBrush]作为的SolidColorBrush
并试图发现其财产,但没有任何工作。
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.
在WinRT的XAML,我们有这个新的 ThemeResource
自动更新的资源。棘手位是找到绑定 ApplicationView.GetForCurrentView()的方法。TitleBar.BackgroundColor
到 SystemControlBackgroundAccentBrush
。
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
.
在我回答这个问题,我创建了一个行为
是一个附加的自定义的 TitleBar中
页面。如果修改背景
属性来这样的事情 -
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 -
基本上你的情况,你只需要创建一个类似(安培;简单)行为
,像一座桥的行为联系起来的 BackgroundColor中
的标题栏
到 SystemControlBackgroundAccentBrush
,通过 ThemeResource
绑定。
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.
希望这有助于!
这篇关于C#检测口音颜色变化的WinRT XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!