return to previous window on WPF

后端 未结 2 1007
一向
一向 2021-01-15 03:15

I\'m new to WPF and couldn\'t find an answer to to this issue:

I have 3 windows I want to navigate between- MainWindow -> Window1 -> Window2

2条回答
  •  独厮守ぢ
    2021-01-15 03:59

    Change the way you show your windows like this:

    private void Window1_Click(object sender, RoutedEventArgs e)
    {
        Hide();
        new Window1().ShowDialog();
        ShowDialog();
    }
    

    And use the DialogResult property to hide your windows (except the main window):

    private void btn_Cancel_Click(object sender, RoutedEventArgs e)
    {
        DialogResult = false;
    }
    

提交回复
热议问题