How do I open a second window from the first window in WPF?

前端 未结 9 1406
一个人的身影
一个人的身影 2020-11-29 20:46

I am new to WPF. I have two windows, such as window1 and window2. I have one button in window1. If I click that button, the window2 has to open. What should I do for that?

9条回答
  •  无人及你
    2020-11-29 21:09

    You will need to create an instance of a new window like so.

    var window2 = new Window2();
    

    Once you have the instance you can use the Show() or ShowDialog() method depending on what you want to do.

    window2.Show();
    

    or

    var result = window2.ShowDialog();
    

    ShowDialog() will return a Nullable if you need that.

提交回复
热议问题