UWP 向 NavigationView 添加额外的选项
UWP Adding Extra Options to the NavigationView
我有以下 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 中。
我想知道是否可以向导航视图添加额外的选项,例如设置上方的更多选项和顶部的图标等。示例如下图所示:
感谢您的建议
我建议您使用在 WinUI 库的预览版中发布的最新 NavigationView 控件,它还向后兼容 Anniversary 更新它在左窗格中具有更大的灵活性,例如放置额外的内容、页眉、页脚甚至带页眉的分组项目等等。
https://docs.microsoft.com/en-us/uwp/toolkits/winui/
您可以尝试在 Windows 控件示例的开发分支中查看示例代码。 ( link 在上面提供的文档中可用)
希望对您有所帮助!
我有以下 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 中。
我想知道是否可以向导航视图添加额外的选项,例如设置上方的更多选项和顶部的图标等。示例如下图所示:
感谢您的建议
我建议您使用在 WinUI 库的预览版中发布的最新 NavigationView 控件,它还向后兼容 Anniversary 更新它在左窗格中具有更大的灵活性,例如放置额外的内容、页眉、页脚甚至带页眉的分组项目等等。
https://docs.microsoft.com/en-us/uwp/toolkits/winui/
您可以尝试在 Windows 控件示例的开发分支中查看示例代码。 ( link 在上面提供的文档中可用) 希望对您有所帮助!