简体   繁体   English

如何使用 NavigationMenu 在 Frame 内的页面之间导航

[英]How to navigate between pages inside Frame with a NavigationMenu

I have a project with 3 different pages to be eventually loaded within a Frame.我有一个包含 3 个不同页面的项目,最终将在一个框架中加载。 In Frame1 how can I use a click event to navigate to a different page inside the Frame (ie Frame 3)?在 Frame1 中,如何使用单击事件导航到 Frame 内的不同页面(即 Frame 3)?

XAML XAML

<NavigationView Name="NavView">
    <Frame Name="myFrame"/>
</NavigationView>

XAML.CS XAML.CS

public MainPage()
    {
        this.InitializeComponent();
        myFrame.Navigate(typeof(Frame1));
    }

Frame1.xaml框架1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
    <Button Name="Button1" Text="Frame 3"/>
</Grid>

Frame2.xaml框架2.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>

Frame3.xaml框架3.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>

In Frame1 how can I use a click event to navigate to a different page inside the Frame (ie Frame 3)?在 Frame1 中,如何使用单击事件导航到 Frame 内的不同页面(即 Frame 3)?

Frame1.xaml框架1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
    <Button Name="Button1" Text="Frame 3"/>
</Grid>

You could add the Click event handler for Button then process the navigation in the code behind.您可以为 Button 添加Click事件处理程序,然后在后面的代码中处理导航。 If you want to navigate to Frame3 page from Frame1 page, you could use Frame1 page Frame property to navigate.如果要从 Frame1 页面导航到 Frame3页面,可以使用 Frame1 页面的Frame属性进行导航。

private void Button_Click(object sender, RoutedEventArgs e)
{
    Frame.Navigate(typeof(Frame3));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM