WPF: Click button and open new window different options


I'd like to make an application, where I can click a button and a new window appears, where new options/buttons are available. I already managed to create a new window win2 after clicking the button:

    private void button1_Click(object sender, RoutedEventArgs e)
        var win2 = new Window();                   

Now how do I edit the new window. Let's say I want to make new buttons (named: blue, green….), where the user can chose a color for the background.

Best Solution

When you want to create a new Window, you cannot use the Window class directly because it acts as a template.

To add a new Window to your project:

Right Click on your Project --> Add --> New Element --> Window. Name it as you please, but I will use the default (Window1).

Now you can operate on your new window in the same ways you did your original window. Add any UI elements you like and code them to your desire.

To show the new window:

Window1 secondWindow = new Window1();
Related Question