本文介绍了UWP 更改 NavigationViewItem 高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上图中,您可以看到我的应用(左)和 Groove Player(右).我想让 NavigationViewItem 的高度像 Groove Player 一样大,但我不知道如何.我尝试使用 Padding 和 MinHeight 但它看起来不一样.

On the image above, you can see my app (left) and Groove Player (right). I want to make NavigationViewItem height big like Groove Player, but I don't know how. I tried playing with Padding and MinHeight but it doesn't look the same.

我想对 AutoSuggestBox 和设置按钮执行相同的操作,它们是 NavigationView 的一部分.

I want to do the same for the AutoSuggestBox and the Settings button, that are part of NavigationView.

    <NavigationView x:Name="navView" IsSettingsVisible="True">
        <NavigationView.AutoSuggestBox>
            <AutoSuggestBox QueryIcon="Find" PlaceholderText="Search"></AutoSuggestBox>
        </NavigationView.AutoSuggestBox>

        <NavigationView.MenuItems>
            <NavigationViewItem x:Name="button1" Icon="Favorite" Content="Button 1" Tapped="Button1_Tapped"/>
            <NavigationViewItem x:Name="button2" Icon="Save" Content="Button 2" Tapped="Button2_Tapped"/>
        </NavigationView.MenuItems>
    </NavigationView>

推荐答案

根据您的要求,您可以编辑 NavigationViewItem 模板.右键单击 xaml 设计器中的 NavigationViewItem -> 编辑模板 -> 编辑副本.

For your requirement, you could edit NavigationViewItem template. Right click NavigationViewItem in the xaml designer -> Edit Template -> Edit a copy.

如果你想改变NavigationViewItem的高度,你可以修改LayoutRoot的高度.然后相应修改SelectionIndicator高度.

If you want to change NavigationViewItem height, you could modify LayoutRoot height. And then modify SelectionIndicator height correspondingly.

<Grid x:Name="LayoutRoot" Background="{TemplateBinding Background}" Height="50" Control.IsTemplateFocusTarget="True">
 ......
<Rectangle x:Name="SelectionIndicator" Fill="{ThemeResource NavigationViewSelectionIndicatorForeground}" Height="40" Opacity="0.0" Width="6"/>

这篇关于UWP 更改 NavigationViewItem 高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-04 22:10