当 IsPaneToggleButtonVisible 为 false 时,NavigationView 不显示 PaneHeader

NavigationView does not show PaneHeader when IsPaneToggleButtonVisible is false

我的 UWP 应用中的 NavigationView 控件有问题。当我将 IsPaneToggleButtonVisible 设置为 false 时,我的 PaneHeader 也会崩溃。正式这个错误是 solved,我做错了什么吗?

<NavigationView PaneDisplayMode="Left" IsPaneToggleButtonVisible="False" IsBackButtonVisible="Collapsed" OpenPaneLength="200" IsSettingsVisible="False" Height="923">
                            <NavigationView.PaneHeader>
                                <Image x:Name="Header" Source="/Assets/Header.png" Stretch="UniformToFill" Margin="0,0,0,0" HorizontalAlignment="Left" Width="216" Height="53"/>
                            </NavigationView.PaneHeader>
<NavigationView/>

基于此thread,它提到

This issue was addressed in #1083, which has now been successfully released as Microsoft.UI.Xaml v2.2.190731001-prerelease.

这意味着该错误已在 Windows UI 库版本的 NavigationView 中解决,因此如果要显示 PaneHeader,需要安装 Microsoft.UI.Xaml nuget package 然后添加<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/> 到你的 Application.Resources.

.App.xaml:

<Application>
    <Application.Resources>
        <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /> 
    </Application.Resources>
</Application>

.MainPage.xaml:

<Page
    ......
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    >

    <Grid>
        <muxc:NavigationView PaneDisplayMode="Left" IsPaneToggleButtonVisible="False" IsBackButtonVisible="Collapsed" OpenPaneLength="200" IsSettingsVisible="False" Height="923">
            <muxc:NavigationView.PaneHeader>
                <Image x:Name="Header" Source="Assets/StoreLogo.png" Stretch="UniformToFill" Margin="0,0,0,0" HorizontalAlignment="Left" Width="53" Height="53"/>
            </muxc:NavigationView.PaneHeader>
        </muxc:NavigationView>
    </Grid>
</Page>