/// <summary> /// Shows a validation failure. /// </summary> /// <param name="validationFailure">Information about the validation failure, including the element on which to show the validation and the validation result.</param> public void ShowValidationFailure(ValidationElementResult validationFailure) { var errorTemplate = ValidationScope.GetValidationTemplate(validationFailure.Element); if (errorTemplate != null) { var adornerLayer = AdornerLayer.GetAdornerLayer(validationFailure.Element); if (adornerLayer != null) { validationFailure.Element.Loaded += Element_Loaded; FocusExtensions.Monitor(validationFailure.Element); var existingAdorner = validationFailure.Element.GetValue(ValidationErrorAdornerProperty) as TemplatedAdorner; if (existingAdorner != null) { // Update the message displayed in the existing adorner existingAdorner.DataContext = validationFailure.Result.Message; } else { var adorner = new TemplatedAdorner(validationFailure.Element, validationFailure.Result.Message, errorTemplate); adornerLayer.Add(adorner); validationFailure.Element.SetValue(ValidationErrorAdornerProperty, adorner); } } } }
private void SetUpAdorner() { DragDropAdornerTemplate Template = this.Element.TryFindResource(new ComponentResourceKey(typeof(DragDrop), typeof(TPanelType))) as DragDropAdornerTemplate ?? this.Element.TryFindResource(new ComponentResourceKey(typeof(DragDrop), typeof(object))) as DragDropAdornerTemplate; this.adornerData = new PanelAdornerData(this.GetOrientation()); this.adorner = new TemplatedAdorner(this.Element, Template, this.adornerData); AdornerLayer.GetAdornerLayer(this.Element).Add(this.adorner); }
/// <summary> /// Implemented by derived classes to set up an adorner that visualizes UI feedback for drap'n'drop oeprations on this element /// </summary> protected override void SetUpAdorner() { DragDropAdornerTemplate Template = this.Element.TryFindResource(new ComponentResourceKey(typeof(DragDrop), typeof(UIElement))) as DragDropAdornerTemplate ?? this.Element.TryFindResource(new ComponentResourceKey(typeof(DragDrop), typeof(object))) as DragDropAdornerTemplate; AdornerLayer AdornerLayer = AdornerLayer.GetAdornerLayer(this.Element); if (AdornerLayer != null) { this.adorner = new TemplatedAdorner(this.Element, Template, null); AdornerLayer.Add(this.adorner); } }
private static void ShowValidationAdornerHelper(DependencyObject targetElement, DependencyObject adornerSite, bool show, bool tryAgain) { UIElement siteUIElement = adornerSite as UIElement; if (siteUIElement != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(siteUIElement); if (adornerLayer == null) { if (tryAgain) { // try again later, perhaps giving layout a chance to create the adorner layer adornerSite.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(ShowValidationAdornerOperation), new object[] { targetElement, adornerSite, show }); } return; } TemplatedAdorner validationAdorner = siteUIElement.ReadLocalValue(ValidationAdornerProperty) as TemplatedAdorner; if (show && validationAdorner == null) { // get the template from the site, or from the target element ControlTemplate validationTemplate = GetErrorTemplate(siteUIElement); if (validationTemplate == null) { validationTemplate = GetErrorTemplate(targetElement); } if (validationTemplate != null) { validationAdorner = new TemplatedAdorner(siteUIElement, validationTemplate); adornerLayer.Add(validationAdorner); siteUIElement.SetValue(ValidationAdornerProperty, validationAdorner); } } else if (!show && validationAdorner != null) { validationAdorner.ClearChild(); adornerLayer.Remove(validationAdorner); siteUIElement.ClearValue(ValidationAdornerProperty); } } }
// Token: 0x0600597E RID: 22910 RVA: 0x0018B1FC File Offset: 0x001893FC private static void ShowValidationAdornerHelper(DependencyObject targetElement, DependencyObject adornerSite, bool show, bool tryAgain) { UIElement uielement = adornerSite as UIElement; if (uielement != null) { AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(uielement); if (adornerLayer == null) { if (tryAgain) { adornerSite.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(Validation.ShowValidationAdornerOperation), new object[] { targetElement, adornerSite, show }); } return; } TemplatedAdorner templatedAdorner = uielement.ReadLocalValue(Validation.ValidationAdornerProperty) as TemplatedAdorner; if (show && templatedAdorner == null) { ControlTemplate errorTemplate = Validation.GetErrorTemplate(uielement); if (errorTemplate == null) { errorTemplate = Validation.GetErrorTemplate(targetElement); } if (errorTemplate != null) { templatedAdorner = new TemplatedAdorner(uielement, errorTemplate); adornerLayer.Add(templatedAdorner); uielement.SetValue(Validation.ValidationAdornerProperty, templatedAdorner); return; } } else if (!show && templatedAdorner != null) { templatedAdorner.ClearChild(); adornerLayer.Remove(templatedAdorner); uielement.ClearValue(Validation.ValidationAdornerProperty); } } }
private static void OnIsValidChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var frameworkElement = (FrameworkElement)sender; if ((bool)e.NewValue) { var adorner = GetAdorner(frameworkElement); if (adorner != null) { adorner.Visibility = Visibility.Collapsed; } } else { var adorner = GetAdorner(frameworkElement); if (adorner == null) { adorner = new TemplatedAdorner(frameworkElement, GetErrorTemplate(frameworkElement)); SetAdorner(frameworkElement, adorner); } adorner.Visibility = Visibility.Visible; } }
private static void SetAdorner(FrameworkElement target, TemplatedAdorner value) { target.SetValue(AdornerProperty, value); }
private static void AddAdorner(FrameworkElement element, object dataContext) { ControlTemplate template = GetValidationTemplate(element); if (template == null) return; AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(element); if (adornerLayer != null) { var adorner = new TemplatedAdorner(element, dataContext, template); adornerLayer.Add(adorner); element.SetValue(ValidationErrorAdornerProperty, adorner); } }