Reputation: 21
Im new to WPF. I want to redirect from one form to another form by clicking on a button. Is this possible in WPF. Please help me in this.
Upvotes: 2
Views: 17098
Reputation: 1
The above-mentioned method will work for windows only. If we have to do page redirection then need to use the below method. This will work smoothly. NavigationService.Navigate(new LatestActiveUsers());
The main benefit of this method is you can choose the page from another folder also. NavigationService.Navigate(new Settings.LatestActiveUsers());
Upvotes: 0
Reputation: 7653
It is possible and there are various ways of achieving this...
If you create a new WPF project in VS it will create a MainWindow. Add a new window, by default it will be called Window1. If you place a button on MainWindow and under the click event of the button put the following code...
private void button1_Click(object sender, RoutedEventArgs e)
{
Window1 NewWindow = new Window1();
NewWindow.Show();
}
This will show Window1.
Basically you are creating a new instance of the Window1 class.
Upvotes: 1
Reputation: 484
Forms in WPF are referred as Windows. Window.Show will let you open/show the new window. For example: Lets assume there are two windows WindowOne and WindowTwo both are derived from Window. so the code would look like:
WindowOneButton_Click(object sender, MouseButtonEventArgs e)
{
WindowTwo windowTwo = new WindowTwo();
//this will open your child window
windowTwo .Show();
//this will close parent window. windowOne in this case
this.Close();
}
Hope this helps.
Upvotes: 3