Nathan Chan
Nathan Chan

Reputation: 303

Error Opening Secondary Window in WPF

I'm using WPF. I have a window named NewWindow.xaml, and I want it to open when the user presses a button in a separate Window. This is what I have:

    private void Button(object sender, CanExecuteRoutedEventArgs e)
    {
        e.CanExecute = true;

        NewWindow.Show();
    }

Although, it gives me an error and says I can simplify it. Then, it doesn't do anything. What can I do?

Upvotes: 1

Views: 92

Answers (1)

Archimedes
Archimedes

Reputation: 231

Try this instead of your code in that method:

NewWindow yourInstanceOfTheNewWindow = new NewWindow();
yourInstanceOfTheNewWindow.Show();

Click here and here for more Information.

Upvotes: 2

Related Questions