简体   繁体   English

从用户控件导航到页面

[英]navigate from usercontrol to page

I have a usercontrol page with the following code 我有一个带有以下代码的用户控制页面

private void StackPanel_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
  Uri uri = new Uri("/News.xaml", UriKind.Relative);

  if (uri != (Application.Current.RootVisual as PhoneApplicationFrame).CurrentSource)
  {
    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(uri);
  }
}

But if I navigate to the page it gives a navigation error. 但是,如果我导航到该页面,则会出现导航错误。 But if it navigate to other page it does work. 但是,如果它导航到其他页面,它将起作用。 What could be the problem? 可能是什么问题呢?

Better use this navigation: 最好使用以下导航:

private void StackPanel_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
   Uri uri = new Uri("/News.xaml", UriKind.Relative);
   if (uri != (Application.Current.RootVisual as PhoneApplicationFrame).CurrentSource)
   {
       NavigationService.navigate(uri);
   }
}

and make sure that News.xaml exists and it is in the root directory of the solution. 并确保News.xaml存在并且位于解决方案的根目录中。

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

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