简体   繁体   English

如何在 windows 通用应用程序中的页面之间导航?

[英]How to navigate between pages in windows universal app?

I am creating a Quiz program which contains many subjects.我正在创建一个包含许多主题的测验程序。 But I struck at the following stage.但我在接下来的阶段进行了打击。 I created many pages and want to load them based on the subject selected.我创建了许多页面,并希望根据所选主题加载它们。 But I don't know how to make it.但我不知道如何制作。

Here is what I wanted.这是我想要的。

在此处输入图片说明

Here Play,Settings and Exit are buttons in main screen.这里播放、设置和退出是主屏幕中的按钮。 Once you click Play it will show you different subjects available.单击“播放”后,它会向您显示可用的不同主题。 Once you select the subjects you have different options too.选择科目后,您也有不同的选择。

at first I created Single page and I used grids with hide and show options.起初我创建了单页,并使用了带有隐藏和显示选项的网格。 But its kind of buggy.但它的那种马车。 So I created pages but I don't know how to navigate between the pages.所以我创建了页面,但我不知道如何在页面之间导航。

How can I achieve it.?我怎样才能实现它。?

@Ajit, @阿吉特,

Yes you can navigate between Pages using :是的,您可以使用以下方法在页面之间导航:

 currentFrame.Navigate(typeof(NextPage));

If currentPage is not this, you can find it the following helper class.如果 currentPage 不是这个,你可以在下面的帮助类中找到它。
It allows to navigate, even from a ViewModel class :它允许导航,甚至从 ViewModel 类:

public class NavigationExtension
{
    public static void Navigate(Type typeOfPage)
    {
        Windows.UI.Xaml.Window window = Windows.UI.Xaml.Window.Current;
        if (window != null)
        {
            Windows.UI.Xaml.Controls.Frame frame = window.Content as Windows.UI.Xaml.Controls.Frame;
            if (frame != null)
            {
                frame.Navigate(typeOfPage);
            }
        }
    }
}

Regards问候

If you want to go to another page and don't want to come back, use this code:如果您想转到另一个页面并且不想回来,请使用以下代码:

Frame rootFrame = Window.Current.Content as Frame;
rootFrame.Navigate(typeof(Your Page Name));

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

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