NavigationView.Content中不需要的边距

时间:2018-08-19 05:42:32

标签: xaml uwp uwp-xaml navigationview

我做了一个简单的应用程序,什么也不做。它仅显示一个包含两个项目的NavigationView和一个TextBlock作为其内容。这是代码:

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

    <Grid>
        <NavigationView>
            <NavigationView.MenuItems>
                <NavigationViewItem Content="First Item" />
                <NavigationViewItem Content="Second Item" />
            </NavigationView.MenuItems>

            <TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="Welcome to my Page"/>
        </NavigationView>
    </Grid>
</Page>

我的应用程序如下所示: Screenshot

为什么TextBlock的顶部有多余的空间?以及如何删除该空间?我知道这是可能的,因为新闻应用程序使用NavigationView并且没有垂直边距。这是其屏幕截图:

News app screenshot

1 个答案:

答案 0 :(得分:1)

您需要将AlwaysShowHeader属性设置为False:

<NavigationView AlwaysShowHeader="False">

这是在docs here中调用的,尽管new preview version似乎当前正在改变这种行为,并且默认情况下不显示任何标题。