Window
单击确定/取消后关闭孩子。
我正在从父 mvm 模型调用子窗口:
//parent view model
var optionSetViewModel = new OptionSetViewModel();
var optionSet = new OptionSet();
optionSet.SetViewModel(optionSetViewModel);
optionSet.SetOwner(_componentview);
optionSet.ShowDialog();
child 的 ok 和 cancel 的代码Window
写在子视图模型中:
private void OkClick()
{
_childWindow.Close();
}
它关闭得很好,但是当它从调用它的位置返回到父视图模型时关闭后,它会抛出空引用异常。关闭后,我正在访问子窗口值:
_someText = optionSetViewModel.SomeText;
_noteText = optionSetViewModel.NoteText;
_optionsetLanguage = optionSetViewModel.OptionSetSelectedItem;
_optionsetselected = optionSetViewModel.OptionSetSelected.ToString();