我在项目中创建第二个NavigationView实例时遇到问题。在学习UWP时,我一直在广泛使用AppUIBasics,并注意到按照此示例,它在Frames中嵌套了NavigationViews:
我一直无法复制它。
我的用例如下:
Id不会引发任何语法错误或XAML错误,但我不确定是怎么回事 我选择了我认为有用的东西:
主页导航XAML
<!-- Navigation view Variable decleration -->
<NavigationView IsSettingsVisible="False"
PaneTitle="Menu"
x:Name="NavView"
Loaded="NavView_Loaded"
IsBackButtonVisible="Collapsed"
PaneDisplayMode="Left"
PaneClosed="NavView_PaneClosed"
AlwaysShowHeader="True"
SelectionChanged="NavView_SelectionChanged" Foreground="{StaticResource DefaultTextColour}">
<!-- All navigation view Items nested within here -->
<NavigationView.MenuItems>
// Removed un-necessary menuitems here
</NavigationView.MenuItems>
<!-- Navigation pane footer -->
<NavigationView.PaneFooter>
<StackPanel Orientation="Vertical" Margin="0,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" x:Name="AppBarButtons" Tag="AppBarButtonPanel" Visibility="{Binding ElementName=NavView, Path=IsPaneOpen}" Margin="16,0,16,0" Height="50">
// THIS IS THE NAVIGATION TO THE SETTINGS PAGE
<AppBarButton Icon="Setting" Margin="1, 2, 0, 0" Tag="Settings_Page" HorizontalAlignment="Center" Width="56.5" Height="40.5" ClickMode="Press" Click="SettingsButton_Click" ToolTipService.ToolTip="Budget Settings"/>
</StackPanel>
</StackPanel>
</NavigationView.PaneFooter>
<!-- Defining the ContentFrame Transition effect-->
<Frame x:Name="ContentFrame">
主页导航XAML(仅设置按钮)
// BUTTON CLICK HANDLERS HERE
private void SettingsButton_Click(object sender, RoutedEventArgs e)
{
ContentFrame.Navigate(typeof(Content_Pages.SettingsPage));
NavView.IsPaneOpen = false;
}
Settings_Page XAML
<Grid>
<muxcontrols:NavigationView PaneDisplayMode="Top"
IsBackButtonVisible="Collapsed"
IsSettingsVisible="False"
x:Name="SettingNavView"
SelectionChanged="SettingNavView_SelectionChanged"
Foreground="{StaticResource DefaultTextColour}"
Grid.Row="0">
<NavigationView.MenuItems>
<NavigationViewItem Content="File Properties" x:Name="FileProperties" Tag="FileProperties_Page"/>
<NavigationViewItem Content="UI Customisation" x:Name="UICustomisation" Tag="UICustomisation_Page"/>
</NavigationView.MenuItems>
</muxcontrols:NavigationView>
<Frame x:Name="SettingsContent"/>
</Grid>
设置页面代码背后:
public sealed partial class SettingsPage : Page
{
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// Navigate to the Home Page
Frame.Navigate(typeof(Content_Pages.SettingsPageContent.FileProperties_Page));
}
private void SettingNavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
NavigationViewItem item = args.SelectedItem as NavigationViewItem;
if(item != null)
{
switch (item.Tag.ToString())
{
case "FileProperties_Page":
SettingsContent.Navigate(typeof(Content_Pages.SettingsPageContent.FileProperties_Page));
break;
case "UICustomisation_Page":
SettingsContent.Navigate(typeof(Content_Pages.SettingsPageContent.UICustomisation_Page));
break;
}
}
}
}
如果我没有提供太多信息,请告诉我。我将其重新添加。如果需要进一步说明,请告诉我。