private static void IsShowChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e) { BadgeAdorner adorner = BadgeAdorner.GetAdorner(d); if (adorner == null) { return; } if ((bool)e.NewValue) { adorner.ShowAdorner(); } else { adorner.HideAdorner(); } }
private static void BadgeTypeChangeCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { BadgeAdorner adorner = BadgeAdorner.GetAdorner(d); if (adorner == null) { return; } if ((BadgeType)e.NewValue == BadgeType.Dot) { adorner.SowDot(); } else { adorner.ShowNormal(); } }
private static void HasAdornerChangedCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e) { var element = d as FrameworkElement; if ((bool)e.NewValue) { if (element != null) { var adornerLayer = AdornerLayer.GetAdornerLayer(element); if (adornerLayer != null) { adornerLayer.Add(new BadgeAdorner(element as UIElement)); } else { //layer为null,说明还未load过(整个可视化树中没有装饰层的情况不考虑) //在控件的loaded事件内生成装饰件 element.Loaded += (s1, e1) => { var adorner = new BadgeAdorner(element); AdornerLayer.GetAdornerLayer(element).Add(adorner); }; } } } else { //装饰件不可用,移除装饰件 AdornerLayer layer = AdornerLayer.GetAdornerLayer(element); if (layer != null) { Adorner[] AllAdorners = layer.GetAdorners(element); if (AllAdorners != null) { IEnumerable <Adorner> desAdorners = AllAdorners.Where(p => p is BadgeAdorner); if (desAdorners != null && desAdorners.Count() > 0) { desAdorners.ToList().ForEach(p => layer.Remove(p)); } } } } }