0

I've tried a number of approaches to this, but when trying to navigate between one page and another in Windows 10 I'm getting some strange behaviour. I display my first page in app.xaml.cs:

View.MainPageView mp = new View.MainPageView();
Window.Current.Content = mp;

This displays the main page fine; however, I have a command that does effectively the same thing for my second page:

View.SecondView dv = new View.SecondView();
Window.Current.Content = dv;

What happens is that it displays the second page, but it is blank. When I try to inspect it using XAML Spy, it shows that the page is there; however, there is no content for it at all (that is, no controls showing).

Is there something particular about Windows 10 that might explain this or, alternatively, is there something about overriding the content in this way that might explain this behaviour?

EDIT:

It appears that the issue is caused by using a bound command, rather than a handled even in order to navigate; the following code works on a click event:

Frame rootFrame = Window.Current.Content as Frame;

rootFrame.Navigated += RootFrame_Navigated;
rootFrame.Navigate(typeof(View.SecondView), null);            

But when called from a bound command, whilst it still shows the view, it is always blank. I initially thought this might be relating to the calling thread, but using the UI thread dispatcher makes no difference.

4

1 回答 1

2

Windows 10 使用与 8.1 相同的方法。

如果你在 Visual Studio 中创建一个新项目并打开 App.xaml.cs,你可以找到那里的OnLaunched方法。在此方法中,您可以看到Frame创建实例并分配给Window.Current.Content. Frame将帮助您管理整个导航。此方法的最后是导航到 MainPage。

rootFrame.Navigate(typeof(MainPage), e.Arguments);

如果要从主页导航到第二页,则必须使用:

Frame.Navigate(typeof(SecondPage));

要返回主页,只需调用:

if (Frame.CanGoBack)
{
    Frame.GoBack();
}
于 2015-11-11T19:14:47.087 回答