Modern UI how to go to another page from another link

别说谁变了你拦得住时间么 提交于 2019-12-01 01:00:45
corradolab

You are mixing "page" navigation with "tab" navigation inside the ModernTab control.

If you call NavigationCommands.GoToPage.Execute inside a ModernTab control you are changing the current "tab", not the current "page".

To change the top level page you can use:

IInputElement target = NavigationHelper.FindFrame("_top", this);
NavigationCommands.GoToPage.Execute("/Pages/BasicPage1.xaml", target);

If the new page is another ModernTab and you want to select a different tab then the default one, then you have to put in place some extra code. In example you could pass parameters to the new page. Se this SO answer.

For anyone that may be struggling with this, set this in your MainWindow.cs constructor:

        Application.Current.MainWindow = this;

Then in the part of your application where you want to navigate to a page, run this:

        IInputElement target = NavigationHelper.FindFrame("_top", Application.Current.MainWindow);
        NavigationCommands.GoToPage.Execute("/NameOfYourPage.xaml", target);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!