UWP向NavigationView添加其他选项

时间:2018-08-13 09:25:41

标签: c# uwp uwp-xaml

我有以下XAML:

<Page
    x:Class="Proto.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Proto"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RenderTransformOrigin="0.5,0.5">
    <Grid>
        <NavigationView IsBackButtonVisible="Collapsed" CompactModeThresholdWidth="9999" ExpandedModeThresholdWidth="9999" CompactPaneLength="96">
            <NavigationView.MenuItems>
                <NavigationViewItem Name="1Item" Content="1" Tag="1Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
                <NavigationViewItem Name="2Item" Content="2" Tag="2Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
                <NavigationViewItem Name="3Item" Content="3" Tag="3Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
                <NavigationViewItem Name="4Item" Content="4" Tag="4Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
                <NavigationViewItem Name="5Item" Content="5" Tag="5Page" FontSize="22" HorizontalAlignment="Center" FontWeight="Bold" Foreground="MediumPurple"/>
            </NavigationView.MenuItems>
        </NavigationView>
    </Grid>
</Page>

C#如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace Proto
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
    }
}

目前,它只是“导航”菜单中的数字,随着我习惯UWP,我只是在进行尝试。我的目标是最新版本的Windows,该版本似乎将一些不错的附加功能集成到UWP中。

我想知道是否有可能在导航视图中添加其他选项,例如设置上方的更多选项和顶部的图标等。一个示例如下图所示:

The Current Layout

感谢您的建议

1 个答案:

答案 0 :(得分:1)

我建议您使用在 WinUI 库的预览版中发布的最新 NavigationView 控件,它与周年更新具有向后兼容性,并且在左窗格中具有更大的灵活性例如放置多余的内容,页眉,页脚,甚至是带有页眉的分组项目等等。

https://docs.microsoft.com/en-us/uwp/toolkits/winui/

您可以尝试在Windows控件示例的dev分支中查看示例代码。 (链接在上面提供的文档中可用) 希望有帮助!