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

ASHOK A picture ASHOK A · Jun 21, 2012 · Viewed 346.4k times · Source

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?

Here is the code I tried:

window2.show();

Answer

Chandru A picture Chandru A · Jun 21, 2012

Write your code in window1.

private void Button_Click(object sender, RoutedEventArgs e)
{
    window2 win2 = new window2();
    win2.Show();
}