Beispiel #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;
                }
            }
        }
Beispiel #2
0
        protected override void OnSelectionChanged()
        {
            // Add adorners for the visual this is representing.
            AdornerLayer adorners = AdornerLayer.GetAdornerLayer(this.Visual);
            UIElement visualElement = this.Visual as UIElement;

            if (adorners != null && visualElement != null)
            {
                if (this.IsSelected && this.adorner == null)
                {
                    Border border = new Border();
                    border.BorderThickness = new Thickness(4);

                    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;
                }
            }
        }