c# - Close child window from parent viewmodel wpf mvvm -


close child window after clicking ok/cancel.

i invoking child window parent mvm model:

//parent view model var optionsetviewmodel = new optionsetviewmodel(); var optionset = new optionset(); optionset.setviewmodel(optionsetviewmodel);  optionset.setowner(_componentview); optionset.showdialog(); 

the code ok , cancel child window written in child view model:

private void okclick() {                _childwindow.close(); } 

it closing fine after closing when returing parent view model called throwing null reference exception. after close accesing child window values:

_sometext = optionsetviewmodel.sometext; _notetext = optionsetviewmodel.notetext; _optionsetlanguage = optionsetviewmodel.optionsetselecteditem; _optionsetselected = optionsetviewmodel.optionsetselected.tostring(); 

with catel (see http://www.catelproject.com/) can close view based on view model. closing view means call this:

mychildviewmodel.closeviewmodel(); 

to show child window:

var mychildviewmodel = new mychildviewmodel(); uivisualizerservice.show(mychildviewmodel); 

Comments