C#Silverlight 3 – 以编程方式在页面之间导航?

假设我有一个包含多个页面的C#Silverlight 3应用程序。 第一页称为Home,第二页称为Details。 导航到详细信息的唯一方法是以编程方式。 我该怎么做呢?! 到处寻找答案,我发现的都是xaml uri mapper实现….

非常感谢

你试过NavigationService吗?

this.NavigationService.Navigate(new Uri(“Details.xaml”,UriKind.Relative));

C#:

this.navContent.Navigate(new Uri("Welcome", UriKind.Relative)); 

XAML:

          

甚至你的“细节”页面也应该被映射(尽管你说的是。)

C#App.Current.Host.NavigationState =“/ Welcome”;

XAML

最好的解决方案是:

将此代码添加到App.xaml.cs:

 private static Grid root; private void Application_Startup(object sender, StartupEventArgs e) { root = new Grid(); root.Children.Add(new MainPage()); this.RootVisual = root; } public static void Navigate(UserControl newPage) { UserControl oldPage = root.Children[0] as UserControl; root.Children.Add(newPage); root.Children.Remove(oldPage); } 

然后,要在页面之间导航,您只需要调用:

 App.Navigate(new OtherSamplePage()); 

试试这个。 这对我有用。

((System.Windows.Controls.Frame)(this.Parent))。导航(new Uri(“/ Import”,UriKind.Relative));