Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i click button i want to redirect from page1.xaml to page2.xaml in windows app for wpf-c#
Posted

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:
C#
Page2 page2Obj = new Page2(); //Create object of Page2
page2Obj.Show(); //Show page2
this.Close(); //this will close Page1
 
Share this answer
 
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);

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..
 
Share this answer
 
v2
Comments
Pratik Bhuva 28-Oct-13 8:12am    
Thanks For the solution...

navService.navigate = (new System.Uri("Page2.xaml",UriKind.AbsoluteOrRelative);
Gives me error like "cannot assign because its a method group.

then i found that This should be....
navService.navigate(new System.Uri("Page2.xaml",UriKind.AbsoluteOrRelative);
(just remove "=").

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900