开发者

To redirect from one page to another page in WPF

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.


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.


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.


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());

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜