示例#1
0
        private static void Update(FrameworkElement target) {
            var layer = AdornerLayer.GetAdornerLayer(target);
            if (layer == null) {
                Dispatcher.CurrentDispatcher.BeginInvoke(new Action<FrameworkElement>(o => Update(o)), DispatcherPriority.Loaded, target);
                return;
            }

            var text = GetText(target);
            var show = GetShow(target);
            var maskType = GetMaskType(target);
            var template = GetContentControlTemplate(target);

            var adorner = GetAdorner(target);

            if (show) {
                if (adorner == null) {
                    adorner = new BusyIndicatorAdorner(target) {
                        MaskType = maskType,
                        ContentControlTemplate = template,
                        Text = text
                    };
                    layer.Add(adorner);
                    SetAdorner(target, adorner);
                } else {
                    adorner.MaskType = maskType;
                    adorner.ContentControlTemplate = template;
                    adorner.Text = text;
                }
                //adorner.Visibility = Visibility.Visible;
            } else {
                if (adorner != null) {
                    layer.Remove(adorner);
                    //如果不 Remove 并设置为 null, 在 使用AvalonDock的程序里,切换标签会使 adorner 的 Parent 丢失
                    //如果设置为 null ,会在再一次显示的时候,重建
                    //adorner.Visibility = Visibility.Collapsed;
                    SetAdorner(target, null);
                }
            }
        }
示例#2
0
 public static void SetAdorner(FrameworkElement target, BusyIndicatorAdorner adorner) {
     target.SetValue(AdornerProperty, adorner);
 }