Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();                   
        win2.Show();
        this.Close();
    }

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.

like image 996
user2240068 Avatar asked Apr 05 '13 14:04

user2240068


1 Answers

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, I will use the default (Window1).

Now you can modify this window in the same way as you did for your original window. Add any UI elements you like and code them to your desire.

To show the new window:

Window1 secondWindow = new Window1();
secondWindow.Show();
like image 132
Andy Avatar answered Nov 16 '22 00:11

Andy