0

在 App.xaml 中定义了 Light 主题 ( <AcrylicBrush TintColor="Red"/>)、Dark、( )。<AcrylicBrush TintColor="Orange"/>根据这篇文章,将 UWP 项目的目标版本从 1803 更改为 1809 会禁用 NavigationView 的丙烯酸纹理 - 为什么?,我将以下内容添加到 ShellPage.xaml。当我在浅色和深色主题之间切换时的预期行为是应用程序NavigationView控件将具有AcrylicBrush在红色和橙色之间切换的色调。在下面的定义中,实际行为是保持橙色。

ShellPage.xaml:

<Page.Resources>
    <StaticResource  x:Key="NavigationViewExpandedPaneBackground"
                     ResourceKey="MyAcrylicBrush"/>
</Page.Resources>

应用程序.xaml:

<Application
x:Class="TEST.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <AcrylicBrush x:Key="MyAcrylicBrush"
                              BackgroundSource="HostBackdrop"
                              TintColor="Green"
                              TintOpacity="0.8" />
                <AcrylicBrush x:Key="NavigationViewDefaultPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Green"
                              TintOpacity="0.8" />
                <AcrylicBrush x:Key="NavigationViewTopPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Green"
                              TintOpacity="0.8" />
                <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Green"
                              TintOpacity="0.8" />
            </ResourceDictionary>
            <ResourceDictionary x:Key="Dark">
                <AcrylicBrush x:Key="MyAcrylicBrush"
                              BackgroundSource="HostBackdrop"
                              TintColor="Orange"
                              TintOpacity="0.8" />
                <AcrylicBrush x:Key="NavigationViewDefaultPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Orange"
                              TintOpacity="0.8" />
                <AcrylicBrush x:Key="NavigationViewTopPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Orange"
                              TintOpacity="0.8" />
                <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Orange"
                              TintOpacity="0.8" />
            </ResourceDictionary>
            <ResourceDictionary x:Key="Light">
                <AcrylicBrush x:Key="MyAcrylicBrush"
                              BackgroundSource="HostBackdrop"
                              TintColor="Red"
                              TintOpacity="1"/>
                <AcrylicBrush x:Key="NavigationViewDefaultPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Red"
                              TintOpacity="1" />
                <AcrylicBrush x:Key="NavigationViewTopPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Red"
                              TintOpacity="1" />
                <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground"
                              BackgroundSource="HostBackdrop"
                              TintColor="Red"
                              TintOpacity="1"/> 
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Application.Resources>
</Application>
4

2 回答 2

2

您可以直接将 Key(NavigationViewExpandedPaneBackGround) 提供给您的 AcrylicBrush。所以它会改变你的导航视图背景。

  <Page.Resources>
      <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Light">
                    <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground" BackgroundSource="HostBackdrop" TintColor="{ThemeResource SystemAccentColorDark1}" FallbackColor="{ThemeResource SystemAccentColorDark1}" TintOpacity="0.80"/>   
                </ResourceDictionary>
                <ResourceDictionary x:Key="Dark">
                    <AcrylicBrush x:Key="NavigationViewExpandedPaneBackground" BackgroundSource="HostBackdrop" TintColor="{ThemeResource SystemAltHighColor}" FallbackColor="#333333" TintOpacity="0.50"/>
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
        </ResourceDictionary>
</Page.Resources>

在此处输入图像描述 希望这能解决您的问题。

于 2019-03-04T07:52:05.743 回答
0

如果您使用StaticResource,它将保持从第一次评估开始刷它。但是,您根本不需要提供资源,ShellPage并且您拥有的内容App.xaml应该足够了-您在NavigationViewExpandedPaneBackground那里调用了一个画笔,并且该画笔应自动覆盖NavigationPane默认值(链接的问题专门讨论了资源名称为不同于内置的)。此外,它应该根据当前主题工作,因为它是主题词典的一部分。

尝试从中删除<StaticResource>元素ShellPage,看看它是否解决了问题。

我测试了这个变化,它工作正常。

轻主题

轻主题

深色主题

深色主题

于 2019-03-04T08:57:11.903 回答