NavigationView.Content 中不需要的边距
Unwanted margin in NavigationView.Content
我制作了一个什么都不做的简单应用程序。它只显示一个包含两个项目的 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>
我的应用程序如下所示:
为什么 TextBlock 的顶部多了一个 space?以及如何删除 space?我知道这是可能的,因为新闻应用程序使用 NavigationView 并且没有垂直边距。这是它的截图:
您需要将 AlwaysShowHeader
属性 设置为 False:
<NavigationView AlwaysShowHeader="False">
这是在 docs here, though the new preview version 中调用的,目前似乎更改了此行为并且默认情况下不显示任何 header。
我制作了一个什么都不做的简单应用程序。它只显示一个包含两个项目的 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>
我的应用程序如下所示:
为什么 TextBlock 的顶部多了一个 space?以及如何删除 space?我知道这是可能的,因为新闻应用程序使用 NavigationView 并且没有垂直边距。这是它的截图:
您需要将 AlwaysShowHeader
属性 设置为 False:
<NavigationView AlwaysShowHeader="False">
这是在 docs here, though the new preview version 中调用的,目前似乎更改了此行为并且默认情况下不显示任何 header。