After abit of back and forth and some good old googling I was able to get the Navigation view to work quiet well (somewhat proud of myself at this point). I have 2 Issues (maybe connected) the primary issue is that any time I select a menu item it correctly navigates however it fails to close/minimize the menu to the left upon selecting the item.(see screenshots bellow) The second issue (which I suspect is connected) the line of code that is supposed to automatically select the homepage when opening the app keeps throwing an exception so I removed the line. The would be line is line 40 on Mainpage.xaml.cs and its contents would be:
if (item is NavigationViewItem && item.Tag.ToString() == "Home_Page")
What it looks like. https://i.imgur.com/a59TATs.png
I tried to set a variable:
NavView.IsPanelOpen = false;
but i cannot find the correct spot to place it
this is the MainPage.xaml
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RussMenu"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-
compatibility/2006"
xmlns:Custom="using:Microsoft.Toolkit.Uwp.UI.Controls"
x:Class="RussMenu.MainPage"
mc:Ignorable="d"
Background="{ThemeResource
ApplicationPageBackgroundThemeBrush}">
<Grid>
<NavigationView x:Name="nvTopLevelNav"
Loaded="nvTopLevelNav_Loaded"
Margin="0,12,0,0"
SelectionChanged="nvTopLevelNav_SelectionChanged"
ItemInvoked="nvTopLevelNav_ItemInvoked"
IsTabStop="False"
>
<NavigationView.MenuItems>
<NavigationViewItem Icon="Home" x:Name="Nav_Home">
<TextBlock Tag="Nav_Home">Home</TextBlock>
</NavigationViewItem>
<NavigationViewItem Icon="SaveLocal"
x:Name="Nav_Submit_COAQC_Results">
<TextBlock Tag="Nav_Submit_COAQC_Results">Submit COA/QC
Results</TextBlock>
</NavigationViewItem>
<NavigationViewItem Icon="Trim"
x:Name="Nav_Edit_Test_Results">
<TextBlock Tag="Nav_Edit_Test_Results">Edit Test
Results</TextBlock>
</NavigationViewItem>
<NavigationViewItem Icon="ReportHacked"
x:Name="Nav_Create_Claims_Ticket">
<TextBlock Tag="Nav_Create_Claims_Ticket">Create Claims
Ticket</TextBlock>
</NavigationViewItem>
<NavigationViewItem Icon="Message"
x:Name="Nav_Message_Page">
<TextBlock Tag="Nav_Message_Page">Contact
Leadership</TextBlock>
</NavigationViewItem>
<NavigationViewItem Icon="Print" x:Name="Nav_Print_Page">
<TextBlock Tag="Nav_Print_Page">Print</TextBlock>
</NavigationViewItem>
<NavigationViewItem Icon="Help" x:Name="Nav_about">
<TextBlock Tag="Nav_about">About</TextBlock>
</NavigationViewItem>
<Image Source="C:
Projects\Russ\RussMenu\RussMenu\Assets\Russell-Standard.jpg">
</Image>
</NavigationView.MenuItems>
<NavigationView.AutoSuggestBox>
<!-- See AutoSuggestBox documentation for
more info about how to implement search. -->
<AutoSuggestBox x:Name="NavViewSearchBox"
QueryIcon="Find"/>
</NavigationView.AutoSuggestBox>
</NavigationView>
<Frame x:Name="contentFrame" HorizontalAlignment="Center"
VerticalAlignment="Center" Margin="50,12,50,50"/>
</Grid>
</Page>
MainPage.xaml.cs
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;
using Microsoft.Data.Sqlite;
// The Blank Page item template is documented at
https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace RussMenu
{
/// <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 string PaneDisplayMode { get; private set; }
public MainPage()
{
this.InitializeComponent();
}
private void nvTopLevelNav_Loaded(object sender, RoutedEventArgs e)
{
// set the initial SelectedItem
foreach (NavigationViewItemBase item in nvTopLevelNav.MenuItems)
{
{
nvTopLevelNav.SelectedItem = item;
break;
}
}
}
private void nvTopLevelNav_SelectionChanged(NavigationView sender,
NavigationViewSelectionChangedEventArgs args)
{
{
}
}
private void nvTopLevelNav_ItemInvoked(NavigationView sender,
NavigationViewItemInvokedEventArgs args)
{
if (args.IsSettingsInvoked)
{
contentFrame.Navigate(typeof(Views.SettingsPage));
}
else
{
TextBlock ItemContent = args.InvokedItem as TextBlock;
if (ItemContent != null)
{
switch (ItemContent.Tag)
{
case "Nav_Home":
contentFrame.Navigate(typeof(Views.HomePage));
break;
case "Nav_about":
contentFrame.Navigate(typeof(Views.About));
break;
case "Nav_Message_Page":
contentFrame.Navigate(typeof(Views.Contact_Leadership));
break;
case "Nav_Create_Claims_Ticket":
contentFrame.Navigate(typeof(Views.CreateClaimsTicket));
break;
case "Nav_Print_Page":
contentFrame.Navigate(typeof(Views.PrintPage));
break;
case "Nav_Submit_COAQC_Results":
contentFrame.Navigate(typeof(Views.submitresults));
break;
case "Nav_Edit_Test_Results":
contentFrame.Navigate(typeof(Views.EditTestResults));
break;
}
}
}
}
}
}
What it should look like. https://i.imgur.com/HYUUhlJ.png
and the Second issue: https://i.imgur.com/H00QztL.png
About the first issue,if you want to it close/minimize the menu to the left upon selecting the item,you can add PaneDisplayMode="LeftCompact" .In addition,the frame you set should be placed inside the NavigationView. In this case, the expanded sidebar will not be masked by the textBlock.
<NavigationView x:Name="nvTopLevelNav"
Loaded="nvTopLevelNav_Loaded"
Margin="0,12,0,0"
SelectionChanged="nvTopLevelNav_SelectionChanged"
ItemInvoked="nvTopLevelNav_ItemInvoked"
IsTabStop="False"
PaneDisplayMode="LeftCompact"
>
...
<Frame x:Name="contentFrame" HorizontalAlignment="Center"
VerticalAlignment="Center" Margin="50,12,50,50"/>
</NavigationView>
About the second issus, the reason for the error is that you did not add a tag to the NavigationViewItem, but added to the textblock.So when you tried to get item.Tag,it will crash.You can correct like below.
<NavigationViewItem Icon="Home" x:Name="Nav_Home" Tag="Nav_Home">
<TextBlock>Home</TextBlock>
</NavigationViewItem>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.