Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to create a new Window from a ViewModel

$
0
0

To create and open a new Window, the Owner of the new Window has to be set to be the object reference of the parent Window from which the new Window is to be opened.

E.g. Without MVVM

private void btnTest_Click(object sender, RoutedEventArgs e)

{

    WdwTestWPFWindow wdwTestChild = new WdwTestWPFWindow(); // A regular XAML WPF window

    wdwTestChild.Owner = wdwParent;  //wdwParent is the current Window from which the test Window is to be opened

   wdwTestChild.ShowDialog();

               wdwTestChild.ShowDialog();

}

How can we do the same thing using MVVM? How can the Owner of the child Window be set in MVVM, given that in MVVM the ViewModel which will be handling the button click event (instead of the code behind) does not have a reference of the View that consumes it and therefore will be unable to set the Owner property of the child Window?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>