Wil*_*ley 3 c# xaml windows-runtime windows-10 uwp
我正在尝试检测Application.Resources资源字典中的更改,因此我可以在更新时自动将Titlebar更改为Accent Color.所有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();
}
Run Code Online (Sandbox Code Playgroud)
我假设它错了,或者我不确定检测更改是否正确.我曾经使用Application.Current.Resources["SystemControlBackgroundAccentBrush"] as SolidColorBrush并尝试检测其属性的前一次迭代,但这也无效.
我究竟做错了什么?请帮忙 :)
这可能没错,但它可能不是最好的解决方案.
在WinRT XAML中,我们有这个新ThemeResource的自动更新资源.棘手的一点是找到绑定ApplicationView.GetForCurrentView().TitleBar.BackgroundColor到的方法SystemControlBackgroundAccentBrush.
在我对这个问题的回答中,我创建了一个Behavior将自定义 附加TitleBar到页面的链接.如果你将Background属性修改为这样的 -
<local:FullScreenModeTitleBarBehavior Background="{ThemeResource SystemControlBackgroundAccentBrush}" />
Run Code Online (Sandbox Code Playgroud)
现在运行应用程序,当您更改accent color系统时,您将看到背景颜色已更新,如下图所示 -
基本上,你的情况,你只需要创建一个类似的(简单?)Behavior这就像一个桥梁,连接了BackgroundColor的TitleBar到SystemControlBackgroundAccentBrush通过,ThemeResource具有约束力.
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
754 次 |
| 最近记录: |