示例#1
0
        protected override void OnSelectionChanged()
        {
            // Add adorners for the visual this is representing.
            var visual_ = Visual as Visual;
            var offset  = new Thickness();

            if (visual_ == null)
            {
                var frec = Visual.Wrap <IFrameworkRenderElementContext>();
                if (frec != null && CommonTreeHelper.IsVisible(frec))
                {
                    FrameworkElement fe = frec.ElementHost.Parent;
                    visual_ = fe;
                    var rect =
                        ((Transform)RenderTreeHelper.TransformToRoot(frec)).TransformBounds(new Rect(frec.RenderSize));
                    offset = new Thickness(rect.Left, rect.Top, fe.RenderSize.Width - rect.Right,
                                           fe.RenderSize.Height - rect.Bottom);
                }
            }
            var adorners      = visual_ == null ? null : AdornerLayer.GetAdornerLayer(visual_);
            var visualElement = visual_ as UIElement;

            if (adorners != null && visualElement != null)
            {
                if (IsSelected && adorner == null)
                {
                    var border = new Border();
                    border.BorderThickness = new Thickness(4);
                    border.Margin          = offset;
                    var borderColor = new Color();
                    borderColor.ScA    = .3f;
                    borderColor.ScR    = 1;
                    border.BorderBrush = new SolidColorBrush(borderColor);

                    border.IsHitTestVisible = false;
                    adorner       = new AdornerContainer(visualElement);
                    adorner.Child = border;
                    adorners.Add(adorner);
                }
                else if (adorner != null)
                {
                    adorners.Remove(adorner);
                    adorner.Child = null;
                    adorner       = null;
                }
            }
        }
示例#2
0
        protected override void OnSelectionChanged()
        {
            // Add adorners for the visual this is representing.
            Visual    visual_ = this.Visual as Visual;
            Thickness offset  = new Thickness();

            if (visual_ == null)
            {
                var frec = (dynamic)this.Visual;
                if (frec != null && CommonTreeHelper.IsVisible(frec))
                {
                    var fe = DXMethods.GetParent(frec.ElementHost);
                    visual_ = fe;
                    var transform = RenderTreeHelper.TransformToRoot(frec).Inverse;
                    var trrec     = transform.TransformBounds(new Rect(fe.RenderSize));
                    offset = new Thickness(-trrec.Left, -trrec.Top, fe.RenderSize.Width - trrec.Right, fe.RenderSize.Height - trrec.Bottom);
                }
            }
            AdornerLayer adorners      = visual_ == null ? null : AdornerLayer.GetAdornerLayer(visual_);
            UIElement    visualElement = visual_ as UIElement;

            if (adorners != null && visualElement != null)
            {
                if (this.IsSelected && this.adorner == null)
                {
                    Border border = new Border();
                    border.BorderThickness = new Thickness(4);
                    border.Margin          = offset;
                    Color borderColor = new Color();
                    borderColor.ScA    = .3f;
                    borderColor.ScR    = 1;
                    border.BorderBrush = new SolidColorBrush(borderColor);

                    border.IsHitTestVisible = false;
                    this.adorner            = new AdornerContainer(visualElement);
                    adorner.Child           = border;
                    adorners.Add(adorner);
                }
                else if (this.adorner != null)
                {
                    adorners.Remove(this.adorner);
                    this.adorner.Child = null;
                    this.adorner       = null;
                }
            }
        }