gpt4 book ai didi

UWP 在导航 View 中使用 Acrylic

转载 作者:行者123 更新时间:2023-12-01 08:46:38 25 4
gpt4 key购买 nike

我正在研究 UWP 的亚克力选项并遇到了一个奇怪的问题。本质上,我试图让导航 View 使用自定义亚克力画笔。但是,主窗口背景比 Navigationview 更透明。
我需要让 NavigationView 与当前主视图一样透明。我附上了一张图片来帮助澄清这一点。很难解释:

Navigation view

正如您在左侧看到的,导航 View 不像右侧的主要功能窗口那样透明。我需要交换它,以便 NavigationView 比 MainPage 更透明。

这是我的 App.XAML

<Application
x:Class="BS.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BS">
<Application.Resources>
<AcrylicBrush x:Key="CustomAcrylicDark"
BackgroundSource="HostBackdrop"
TintColor="Gray"
TintOpacity="0.6"
FallbackColor="Black"/>
<AcrylicBrush x:Key="CustomAcrylicLight"
BackgroundSource="HostBackdrop"
TintColor="White"
TintOpacity="0.6"
FallbackColor="White"/>
</Application.Resources>
</Application>

这是我的 MainPage.XAML
<Page
x:Class="BS.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BS"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
RequestedTheme="Dark"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Page.Resources>

</Page.Resources>
<Grid>
<NavigationView Background="{StaticResource CustomAcrylicDark}" PaneTitle="BS" IsBackButtonVisible="Collapsed" CompactModeThresholdWidth="9999" ExpandedModeThresholdWidth="9999" CompactPaneLength="96">
<NavigationView.MenuItems>
<NavigationViewItem Name="HItem" Content="HOME" Tag="HOME_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItemSeparator/>
<NavigationViewItem Name="OItem" Content="OVERVIEW" Tag="O_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="BItem" Content="BILLS" Tag="B_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="PItem" Content="PEOPLE" Tag="B_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="TItem" Content="TRANSFERS" Tag="T_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="PItem" Content="PAY DATES" Tag="P_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
</NavigationView.MenuItems>
</NavigationView>
</Grid>
</Page>

先感谢您。

最佳答案

NavigationView建立在 Splitview 之上.在 Splitview ,您将找到一个名为 PaneBackground 的属性。但是 NavigationView不会让你设置PaneBackground Splitview 的属性(property)它是在制作的。

但是,在调查 NavigationView 的模板后,您并非不走运。 ,我发现 PaneBackground属性绑定(bind)到 ThemeResource调用NavigationViewDefaultPaneBackground .所以,你的工作是覆盖这个属性。像这样:

<Grid>
<Grid.Resources>
<AcrylicBrush x:Key="NavigationViewDefaultPaneBackground"
BackgroundSource="HostBackdrop"
TintColor="Gray"
TintOpacity="0.6"
FallbackColor="Black"/>
</Grid.Resources>
<NavigationView x:Name="Navview" Background="{StaticResource CustomAcrylicDark}" PaneTitle="BS" IsBackButtonVisible="Collapsed"
CompactModeThresholdWidth="9999" ExpandedModeThresholdWidth="9999" CompactPaneLength="96">

<NavigationView.MenuItems>
<NavigationViewItem Name="HItem" Content="HOME" Tag="HOME_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItemSeparator/>
<NavigationViewItem Name="OItem" Content="OVERVIEW" Tag="O_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="BItem" Content="BILLS" Tag="B_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="PItem" Content="PEOPLE" Tag="B_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="TItem" Content="TRANSFERS" Tag="T_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
<NavigationViewItem Name="PItem2" Content="PAY DATES" Tag="P_Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
</NavigationView.MenuItems>
<Button HorizontalAlignment="Center" Content="{x:Bind Navview.DisplayMode, Mode=OneWay}"/>
</NavigationView>
</Grid>

这给出了以下结果:
enter image description here

因此,您可以使用此方法根据需要设置 Pane 的背景。希望有帮助。

关于UWP 在导航 View 中使用 Acrylic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51860422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com