【问题标题】:Change Hamburger Menu Background in code or settings在代码或设置中更改汉堡菜单背景
【发布时间】:2018-01-03 00:37:22
【问题描述】:

提前致谢。

我在网上搜索了很长时间,坚果没有找到任何东西。请帮助并尝试给出一些想法如何实现这一点。

在 App.xaml 中,我有一个这样的 ResourceDictionary:

<ResourceDictionary x:Key="Light">
        <AcrylicBrush x:Key="NavigationViewDefaultPaneBackground" BackgroundSource="Backdrop" TintColor="White" TintOpacity=".6"/>
        <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground" BackgroundSource="HostBackdrop" TintColor="White" TintOpacity=".8"/>

    </ResourceDictionary>

在微软导航视图网站上说:

它有效,我在 ResourceDictionary 中更改了此颜色,但我想在设置中更改此颜色,我不能。我想做用户自定义。

在代码中,我找不到 Nav View 的 NavigationViewDefaultPaneBackgroundNavigationViewExpandedPaneBackground 属性,只有背景属性

我改变了这个背景,但它是NavPage的背景没有改变。而且这个地方变了:

在代码中,我找不到 Nav View 的 `NavigationView 的背景。

那么,我该怎么做?如何在代码中更改此背景?

或者我如何在ResourceDictionary或设置中编写主题系统?

谢谢。

【问题讨论】:

    标签: c# uwp themes


    【解决方案1】:

    您必须创建一个Acrylic Brush,并将其设置为您的NavigationView 对象的Background 属性。

    查看 Microsoft 关于 NavigationViewAcrylic 的文档

    Generic.xaml 中显示的这两个资源是 NavigationView 对象的 Background 的默认样式实现,当 NavigationView 处于 CompactExpanded 模式时。

    这些不是像 Background property 那样的依赖属性,而是 resources定义了丙烯酸画笔,它们被设置为背景属性NavigationView 默认!,取决于其当前的视觉状态。

    如果你想定义自己的风格,最简单的方法是重用这两个资源,因为它们已经包含在Compact/Expanded模式之间转换的UI逻辑,将背景从In-App acrylic切换到@ 987654334@,以及为什么 BackgroundSourceproperty 值在这 2 个资源定义中设置为不同的值。

    如果您想将 Background Acrylic 的颜色设置为另一种颜色,您必须更改 TintColorTintOpacity 依赖属性。在上面定义的资源中,TintColor 设置为White

    这样,

    <AcrylicBrush x:Key="NavigationViewDefaultPaneBackground" BackgroundSource="Backdrop" TintColor="Blue" TintOpacity=".6"/>
    <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground" BackgroundSource="HostBackdrop" TintColor="Blue" TintOpacity=".8"/>
    

    TintColor 依赖属性设置为 Blue 用于两种背景状态:In-App 和 Background Acrylic,这应该会修改 NavigationView 窗格的颜色。

    如果你想增强你的设置选项,让你的应用在几个状态之间切换,你必须绑定 TintColor

    【讨论】:

    • 我知道了,谢谢,但我不知道如何在 ResourceDictionary 中使用绑定。比如我有一个名为NavStyle的类,它有一个对象是颜色,如何使用绑定TintColor?我尝试过但不工作:TintColor="{x:Bind NavStyle.clolr}",找不到 NavStyle 类。
    • 现在,在 app.xaml.cs 中,我有一个 public static Color color = Windows.UI.Color.FromArgb(System.Drawing.Color.Blue.A, System.Drawing.Color.Blue.R, System.Drawing.Color.Blue.G, System.Drawing.Color.Blue.B);,在 AcrylicBrush 中:&lt;AcrylicBrush x:Key="NavigationViewDefaultPaneBackground" BackgroundSource="Backdrop" TintColor="{Binding color}" TintOpacity=".6"/&gt;,它不起作用,请帮助我,谢谢
    猜你喜欢
    • 2019-09-20
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    相关资源
    最近更新 更多