PuncturedRectangle class.
Inheritance: System.Windows.Shapes.Shape
示例#1
0
        public CroppingAdorner(UIElement adornedElement, Rect rcInit)
            : base(adornedElement)
        {
            _cropMask = new PuncturedRect
            {
                IsHitTestVisible = false,
                Interior         = rcInit,
                Fill             = Fill
            };

            _thumbCanvas = new Canvas
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Stretch
            };

            _visualCollection = new VisualCollection(this)
            {
                _cropMask, _thumbCanvas
            };

            BuildCorner(ref _thumbTop, Cursors.SizeNS);
            BuildCorner(ref _thumbBottom, Cursors.SizeNS);
            BuildCorner(ref _thumbLeft, Cursors.SizeWE);
            BuildCorner(ref _thumbRight, Cursors.SizeWE);
            BuildCorner(ref _thumbTopLeft, Cursors.SizeNWSE);
            BuildCorner(ref _thumbTopRight, Cursors.SizeNESW);
            BuildCorner(ref _thumbBottomLeft, Cursors.SizeNESW);
            BuildCorner(ref _thumbBottomRight, Cursors.SizeNWSE);
            BuildCenter(ref _thumbCenter);

            //Cropping handlers.
            _thumbBottomLeft.DragDelta  += HandleBottomLeft;
            _thumbBottomRight.DragDelta += HandleBottomRight;
            _thumbTopLeft.DragDelta     += HandleTopLeft;
            _thumbTopRight.DragDelta    += HandleTopRight;
            _thumbTop.DragDelta         += HandleTop;
            _thumbBottom.DragDelta      += HandleBottom;
            _thumbRight.DragDelta       += HandleRight;
            _thumbLeft.DragDelta        += HandleLeft;
            _thumbCenter.DragDelta      += HandleCenter;

            //Clipping interior should be withing the bounds of the adorned element.
            var element = adornedElement as FrameworkElement;

            if (element != null)
            {
                element.SizeChanged += AdornedElement_SizeChanged;
            }
        }
示例#2
0
        private static object CoerceRectInterior(DependencyObject d, object value)
        {
            PuncturedRect pr         = (PuncturedRect)d;
            Rect          rcExterior = pr.Exterior;
            Rect          rcProposed = (Rect)value;

            double left   = Math.Max(rcProposed.Left, rcExterior.Left);
            double top    = Math.Max(rcProposed.Top, rcExterior.Top);
            double width  = Math.Min(rcProposed.Right, rcExterior.Right) - left;
            double height = Math.Min(rcProposed.Bottom, rcExterior.Bottom) - top;

            rcProposed = new Rect(left, top, width, height);
            return(rcProposed);
        }
示例#3
0
        public CroppingAdorner(UIElement adornedElement, Rect rcInit)
            : base(adornedElement)
        {
            _cropMask = new PuncturedRect
            {
                IsHitTestVisible = false,
                Interior = rcInit,
                Fill = Fill
            };

            _thumbCanvas = new Canvas
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };

            _visualCollection = new VisualCollection(this)
            { _cropMask, _thumbCanvas};

            BuildCorner(ref _thumbTop, Cursors.SizeNS);
            BuildCorner(ref _thumbBottom, Cursors.SizeNS);
            BuildCorner(ref _thumbLeft, Cursors.SizeWE);
            BuildCorner(ref _thumbRight, Cursors.SizeWE);
            BuildCorner(ref _thumbTopLeft, Cursors.SizeNWSE);
            BuildCorner(ref _thumbTopRight, Cursors.SizeNESW);
            BuildCorner(ref _thumbBottomLeft, Cursors.SizeNESW);
            BuildCorner(ref _thumbBottomRight, Cursors.SizeNWSE);

            //Cropping handlers.
            _thumbBottomLeft.DragDelta += HandleBottomLeft;
            _thumbBottomRight.DragDelta += HandleBottomRight;
            _thumbTopLeft.DragDelta += HandleTopLeft;
            _thumbTopRight.DragDelta += HandleTopRight;
            _thumbTop.DragDelta += HandleTop;
            _thumbBottom.DragDelta += HandleBottom;
            _thumbRight.DragDelta += HandleRight;
            _thumbLeft.DragDelta += HandleLeft;

            //Clipping interior should be withing the bounds of the adorned element.
            FrameworkElement element = adornedElement as FrameworkElement;

            if (element != null)
            {
                element.SizeChanged += AdornedElement_SizeChanged;
            }
        }