WPF应用程序中的页面重定向

问题描述:

当我单击按钮时,我想在Windows应用程序中从页面1.xaml重定向到页面2.xaml,用于wpf-c#

when i click button i want to redirect from page1.xaml to page2.xaml in windows app for wpf-c#

这样做非常简单,下面是代码段:

考虑到您拥有page1.xaml和page2.xaml,您将从page1退出时编写以下代码:
Well that is very simple to do, below is the code snippet:

Considering you have page1.xaml and page2.xaml, you will write this code while exiting from page1:
Page2 page2Obj = new Page2(); //Create object of Page2
page2Obj.Show(); //Show page2
this.Close(); //this will close Page1


用于以编程方式从一个页面导航到另一页面(单击按钮即可发布信息)

For programmatically navigate from one page to another(as you have button click on your post)

NavigationService navService = NavigationService .GetNavigationService(this)
navService.navigate =  (new System.Uri("Page2.xaml",UriKind.AbsoluteOrRelative); 






or

Page2 nextPage = new Page2();
navService.Navigate(nextPage);


或者,您也可以在eventHandlers中使用条件代码来决定要转到哪个页面
WPF导航本质上将是异步的...
希望对您有所帮助.


Or you can you use conditional code in your eventHandlers to decide which page to go
WPF navigation would be async in nature...
Hope that helps..