2
單擊確定/取消後關閉子項Window
。從父視圖關閉子窗口wpf mvvm
我調用從父MVM模型子窗口:
//parent view model
var optionSetViewModel = new OptionSetViewModel();
var optionSet = new OptionSet();
optionSet.SetViewModel(optionSetViewModel);
optionSet.SetOwner(_componentview);
optionSet.ShowDialog();
用於確定的代碼,並取消對兒童Window
是寫在子視圖模型:
private void OkClick()
{
_childWindow.Close();
}
它關閉正常,但後當它回到父視圖模型時從它被調用的位置關閉,它拋出空引用異常。收盤後,我accesing子窗口值:
_someText = optionSetViewModel.SomeText;
_noteText = optionSetViewModel.NoteText;
_optionsetLanguage = optionSetViewModel.OptionSetSelectedItem;
_optionsetselected = optionSetViewModel.OptionSetSelected.ToString();
我們需要看到後'optionSet.ShowDialog()代碼;' – Bolu
更新的代碼PPLS做檢查 – user2189168
你應該讓Messenger類處理ViewModels之間的關閉,它更容易。 – Rudi