protected bool TryClose() { ValidatingDialogHost dialogHost = (ValidatingDialogHost)DialogHost ?? new ValidatingDialogHost(this); IDataErrorInfo validatingDataContext = (IDataErrorInfo)DataContext; if (validatingDataContext != null) { string error = validatingDataContext.Error; if (error != null) { dialogHost.ShowErrorMessage(error, caption: null); return(false); } } if (dialogHost.OnClosing()) { DialogResult = true; return(true); } else { // A confirmation or validation issue is causing the dialog to stay open. return(false); } }
private void Dialog_Loaded(object sender, EventArgs e) { Loaded -= Dialog_Loaded; // This needs to be set in the loaded event, because a call to InitializeComponent // from a child class runs _after_ our constructor, and will set the dialog host to null. DialogHost = new ValidatingDialogHost(this); }
private void Dialog_Loaded(object sender, EventArgs e) { Loaded -= Dialog_Loaded; // This needs to be set in the loaded event, because a call to InitializeComponent // from a child class runs _after_ our constructor, and will set the dialog host to null. DialogHost = new ValidatingDialogHost(this); }