private void ShowWindowDialog_Closing(object a_sender, CancelEventArgs a_e) { Window window = (Window)a_sender; IWindowViewModel viewModel = window.DataContext as IWindowViewModel; if (viewModel == null) { return; } a_e.Cancel = !viewModel.WindowIsClosing(); }