Sipps
Sipps

Reputation: 49

WPF Displaying Windows

I have been looking for a good tutorial on WPF, MVVM and windows navigation. I am trying to display a new window once a user clicks an "ok" button. Does anyone know how to go about doing this?

Upvotes: 1

Views: 76

Answers (1)

failedprogramming
failedprogramming

Reputation: 2522

To display a new window using an OK button, you need to create a new instance of the window and call it's Show() method. You can either do this in the button click event (code behind) or bind it to a custom Command object (MVVM). Here's the code to open a window.

   var window = new MainWindow();
   window.Show();

In MVVM, some developers choose to just have 1 Window, usually MainWindow, and separate parts of their UI into UserControls. They use DataTemplates to define which UserControl appears in the MainWindow.

There are a lot of tutorials on MVVM if you just take time to Google this topic. Here's a few links that have helped me a lot. http://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/ http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

Upvotes: 1

Related Questions