我正在尝试检测 Application.Resources 资源字典中的更改,因此我可以在更新时自动将标题栏更改为强调色。所有 XAML 控件和元素都会自动更改,并且在将纯色画笔设置为 DSDFS 画笔的地址时,其内部值会发生变化。
这是我试图用来检测变化的代码:
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
并尝试检测其属性,但这也不起作用。
我做错了什么?请帮助:)
最佳答案
这可能没有错,但可能不是可用的最佳解决方案。
在 WinRT XAML 中,我们有这个新的 ThemeResource
可以自动更新资源。棘手的一点是找到一种方法将 ApplicationView.GetForCurrentView().TitleBar.BackgroundColor
绑定(bind)到 SystemControlBackgroundAccentBrush
。
在my answer to this question ,我创建了一个 Behavior
将 custom TitleBar
附加到页面。如果您将 Background
属性修改为类似这样的内容 -
<local:FullScreenModeTitleBarBehavior Background="{ThemeResource SystemControlBackgroundAccentBrush}" />
现在运行 app当您更改系统的 accent color
时,您会看到背景颜色会更新,如下图所示 -
基本上在你的情况下,你只需要创建一个类似的(和更简单的?)行为
,它就像一个桥梁来链接 TitleBar 的
到 BackgroundColor
SystemControlBackgroundAccentBrush
,通过 ThemeResource
绑定(bind)。
希望这对您有所帮助!
关于C# 检测强调色更改 WinRT XAML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32626470/