/// <summary> /// Called when a control is being validated. Set e.Cancel to true to cause the validation to fail. /// </summary> /// <param name="sender">The control being validated.</param> /// <param name="e">Parameters for the event.</param> private void HandleControlValidating(object sender, System.ComponentModel.CancelEventArgs e) { Control control = (Control)sender; string propertyName = (string)control.Tag; string value = control.Text; TextBox textBox = control as TextBox; if (textBox != null) { if (!textBox.Modified) { return; } value = this.ParentPropertyPage.Normalize(propertyName, value); } else { FoldersSelector foldesSelector = control as FoldersSelector; if (foldesSelector != null) { value = foldesSelector.TextBox.Text; } } string currentValue = this.ParentPropertyPage.GetProperty(propertyName); if (!String.Equals(value, currentValue, StringComparison.Ordinal)) { try { PropertyValidator.ValidateProperty(propertyName, value); } catch (ProjectPropertyArgumentException ex) { if (textBox != null) { // Don't retrigger Validation when losing focus due to the message box. textBox.Modified = false; } WixHelperMethods.ShowErrorMessageBox(this.ParentPropertyPage.Site, ex.Message); e.Cancel = true; if (textBox != null) { textBox.Text = currentValue; textBox.Modified = false; // Clear the page dirty flag if it was only this textbox that was modified. int isDirty; if (this.ParentPropertyPage.ProjectMgr.IsDirty(out isDirty) == 0 && isDirty == 0) { this.ParentPropertyPage.IsDirty = false; } } } } else if (textBox != null && textBox.Modified) { // The text wasn't significantly changed, but might need to be adjusted to the trimmed value. textBox.Text = value; textBox.Modified = false; // Clear the page dirty flag if it was only this textbox that was modified. int isDirty; if (this.ParentPropertyPage.ProjectMgr.IsDirty(out isDirty) == 0 && isDirty == 0) { this.ParentPropertyPage.IsDirty = false; } } }