Я в основном пытаюсь создать базовое навигационное представление в UWP (Visual studio 2017), но у меня возникают проблемы с этим. Я прошел много уроков и примеров кода, но он не работает.
Когда я запускаю приложение, оно работает, но когда я нажимаю на один из пунктов меню, оно дает мне
System.NullReferenceException
Я искал это онлайн, но нет хороших результатов. Вот что я сделал до сих пор:
XAML:
<Page
x:Class="ICTvOS.Views.SoftwarePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ICTvOS.Views"
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 x:Name="NavView"
Header="Software Download And Installation Center"
PaneDisplayMode="Top"
SelectionChanged="NavView_SelectionChanged">
<NavigationView.MenuItems>
<NavigationViewItemHeader Content="Released"/>
<NavigationViewItem x:Name="p0item" Icon="Help" Tag="P0_Page" Content="None yet."/>
<NavigationViewItemSeparator/>
<NavigationViewItemHeader Content="Beta"/>
<NavigationViewItem x:Name="p1item" Icon="AllApps" Tag="P1_Page" Content="CPU_Build"/>
<NavigationViewItemHeader Content="Planned"/>
<NavigationViewItem x:Name="p2item" Icon="XboxOneConsole" Tag="P2_Page" Content="ICTvOS"/>
</NavigationView.MenuItems>
<NavigationView.AutoSuggestBox>
<AutoSuggestBox x:Name="ASB01" QueryIcon="Find"/>
</NavigationView.AutoSuggestBox>
<Frame x:Name="contentFrame">
<Frame.ContentTransitions>
<TransitionCollection>
<NavigationThemeTransition/>
</TransitionCollection>
</Frame.ContentTransitions>
</Frame>
</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=234238
namespace ICTvOS.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class SoftwarePage : Page
{
public SoftwarePage()
{
this.InitializeComponent();
}
#region NavigationView event handlers
private void NavView_Loaded(object sender, RoutedEventArgs e)
{
}
private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (args.IsSettingsSelected)
{
contentFrame.Navigate(typeof(SettingsPage));
}
else
{
switch (NavView.Tag.ToString())
{
case "P1_Page":
contentFrame.Navigate(typeof(HomePage));
break;
case "P2_Page":
contentFrame.Navigate(typeof(SoftwarePage));
break;
}
}
}
private void NavView_ItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
}
#endregion
}
}
Как я могу это исправить, чтобы он мог правильно отображать страницы?