public static void ApplyIsBusyBehaviour(this FrameworkElement ctrl, ViewModel mdl) { if (ctrl == null) { throw new ArgumentNullException("ctrl"); } if (mdl == null) { throw new ArgumentNullException("mdl"); } mdl.PropertyChanged += (sender, e) => { switch (e.PropertyName) { case "IsBusy": if (mdl.IsBusy) { ContentAdorner.ShowWaitDialog(ctrl); } else { ContentAdorner.HideWaitDialog(ctrl); } break; } }; }
public void ArrangeOverrideWhenChildIsNull() { var textBox = new TextBox(); var adorner = new ContentAdorner(textBox) { Child = null }; var result = ArrangeOverrideMethod.Invoke(adorner, new object[] { new Size(0, 0) }); Assert.AreEqual(new Size(0, 0), result); }
public void ArrangeOverrideWhenChildIsNull() { var textBox = new TextBox(); var adorner = new ContentAdorner(textBox) { Child = null }; var result = ArrangeOverrideMethod.Invoke(adorner, new object[] { new Size(0, 0) }); Assert.AreEqual(new Size(0, 0), result); }
private static void ShowContentAdorner_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { var Element = o as FrameworkElement; if (Element == null) { return; } var Listener = GetContentAdornerDataContextWeakEventListener(Element); if ((bool)e.NewValue) { var AdornerLayer = InitializeAdornerLayerCache(Element); if (AdornerLayer == null) { return; } var ContentAdorner = GetContentAdorner(Element); if (ContentAdorner == null) { ContentAdorner = new ContentAdorner(Element); ContentAdorner.Style = GetContentAdornerStyle(Element); SetContentAdorner(Element, ContentAdorner); } if (ContentAdorner.Parent != AdornerLayer) { AdornerLayer.Add(ContentAdorner); } ContentAdorner.DataContext = Element.DataContext; if (Listener == null) { Listener = new ContentAdornerDataContextWeakEventListener(); } SetContentAdornerDataContextWeakEventListener(Element, Listener); DataContextChangedEventManager.AddListener(Element, Listener); } else { if (Listener != null) { DataContextChangedEventManager.RemoveListener(Element, Listener); SetContentAdornerDataContextWeakEventListener(Element, null); } RemoveContentAdorner(Element); } }
private void Button_Click(object sender, RoutedEventArgs e) { var btn = (Button)sender; var lyr = AdornerLayer.GetAdornerLayer(btn); if (_adorner != null) { lyr.Remove(_adorner); _adorner = null; } else { _adorner = new ContentAdorner(new Button() { Content = "Here could be pretty much anything!" }, btn); _adorner.HorizontalOffset = btn.ActualWidth / 2.0; _adorner.VerticalOffset = btn.ActualHeight; lyr.Add(_adorner); } }
private static void SetIfNotNull( DependencyObject source, DependencyProperty sourceProperty, ContentAdorner adorner, DependencyProperty adornerProperty) { var value = source.GetValue(sourceProperty); if (value != null) { adorner.SetValue(adornerProperty, value); } }
private static void OnIsShowingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var element = (UIElement)d; if (Equals(e.NewValue, true)) { var adorner = element.GetAdorner(); if (adorner == null) { adorner = new ContentAdorner(element); element.SetAdorner(adorner); } SetIfNotNull(d, ContentProperty, adorner, ContentAdorner.ContentProperty); SetIfNotNull(d, ContentTemplateProperty, adorner, ContentAdorner.ContentTemplateProperty); SetIfNotNull(d, ContentTemplateSelectorProperty, adorner, ContentAdorner.ContentTemplateSelectorProperty); SetIfNotNull(d, ContentPresenterStyleProperty, adorner, ContentAdorner.ContentPresenterStyleProperty); AdornerService.Show(adorner); } else { var adorner = element.GetAdorner(); if (adorner != null) { AdornerService.Remove(adorner); } element.ClearValue(AdornerProperty); } }
private static void SetAdorner(this DependencyObject element, ContentAdorner value) { element.SetValue(AdornerProperty, value); }
private void ShowAdorner() { var parent = this.Parent as Panel; this.adorner = new ContentAdorner(parent, this.AdornedContent); // this.adorner = new FrameworkElementAdorner(parent, new LoadingAnimation()); var adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Add(this.adorner); } }
private void HideAdorner() { if (this.adorner == null) { return; } var adornerLayer = AdornerLayer.GetAdornerLayer(this); if (adornerLayer != null) { adornerLayer.Remove(this.adorner); this.adorner.DisconnectChild(); this.adorner = null; } }
internal static void SetContentAdorner(FrameworkElement element, ContentAdorner value) { element.SetValue(ContentAdornerProperty, value); }