コード例 #1
0
ファイル: CroppingAdorner.cs プロジェクト: RudyYang/XPence
        public CroppingAdorner(UIElement adornedElement, Rect rcInit)
            : base(adornedElement)
        {
            _vc         = new VisualCollection(this);
            _prCropMask = new PuncturedRect();
            _prCropMask.IsHitTestVisible = false;
            _prCropMask.RectInterior     = rcInit;
            _prCropMask.Fill             = Fill;
            _vc.Add(_prCropMask);
            _cnvThumbs = new Canvas();
            _cnvThumbs.HorizontalAlignment = HorizontalAlignment.Stretch;
            _cnvThumbs.VerticalAlignment   = VerticalAlignment.Stretch;

            _vc.Add(_cnvThumbs);
            BuildCorner(ref _crtTop, Cursors.SizeNS);
            BuildCorner(ref _crtBottom, Cursors.SizeNS);
            BuildCorner(ref _crtLeft, Cursors.SizeWE);
            BuildCorner(ref _crtRight, Cursors.SizeWE);
            BuildCorner(ref _crtTopLeft, Cursors.SizeNWSE);
            BuildCorner(ref _crtTopRight, Cursors.SizeNESW);
            BuildCorner(ref _crtBottomLeft, Cursors.SizeNESW);
            BuildCorner(ref _crtBottomRight, Cursors.SizeNWSE);

            // Add handlers for Cropping.
            _crtBottomLeft.DragDelta  += new DragDeltaEventHandler(HandleBottomLeft);
            _crtBottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            _crtTopLeft.DragDelta     += new DragDeltaEventHandler(HandleTopLeft);
            _crtTopRight.DragDelta    += new DragDeltaEventHandler(HandleTopRight);
            _crtTop.DragDelta         += new DragDeltaEventHandler(HandleTop);
            _crtBottom.DragDelta      += new DragDeltaEventHandler(HandleBottom);
            _crtRight.DragDelta       += new DragDeltaEventHandler(HandleRight);
            _crtLeft.DragDelta        += new DragDeltaEventHandler(HandleLeft);

            // We have to keep the clipping interior withing the bounds of the adorned element
            // so we have to track it's size to guarantee that...
            FrameworkElement fel = adornedElement as FrameworkElement;

            if (fel != null)
            {
                fel.SizeChanged += new SizeChangedEventHandler(AdornedElement_SizeChanged);
            }
        }
コード例 #2
0
        public CroppingAdorner(UIElement adornedElement, Rect rcInit)
            : base(adornedElement)
        {
            _vc = new VisualCollection(this);
            _prCropMask = new PuncturedRect();
            _prCropMask.IsHitTestVisible = false;
            _prCropMask.RectInterior = rcInit;
            _prCropMask.Fill = Fill;
            _vc.Add(_prCropMask);
            _cnvThumbs = new Canvas();
            _cnvThumbs.HorizontalAlignment = HorizontalAlignment.Stretch;
            _cnvThumbs.VerticalAlignment = VerticalAlignment.Stretch;

            _vc.Add(_cnvThumbs);
            BuildCorner(ref _crtTop, Cursors.SizeNS);
            BuildCorner(ref _crtBottom, Cursors.SizeNS);
            BuildCorner(ref _crtLeft, Cursors.SizeWE);
            BuildCorner(ref _crtRight, Cursors.SizeWE);
            BuildCorner(ref _crtTopLeft, Cursors.SizeNWSE);
            BuildCorner(ref _crtTopRight, Cursors.SizeNESW);
            BuildCorner(ref _crtBottomLeft, Cursors.SizeNESW);
            BuildCorner(ref _crtBottomRight, Cursors.SizeNWSE);

            // Add handlers for Cropping.
            _crtBottomLeft.DragDelta += new DragDeltaEventHandler(HandleBottomLeft);
            _crtBottomRight.DragDelta += new DragDeltaEventHandler(HandleBottomRight);
            _crtTopLeft.DragDelta += new DragDeltaEventHandler(HandleTopLeft);
            _crtTopRight.DragDelta += new DragDeltaEventHandler(HandleTopRight);
            _crtTop.DragDelta += new DragDeltaEventHandler(HandleTop);
            _crtBottom.DragDelta += new DragDeltaEventHandler(HandleBottom);
            _crtRight.DragDelta += new DragDeltaEventHandler(HandleRight);
            _crtLeft.DragDelta += new DragDeltaEventHandler(HandleLeft);

            // We have to keep the clipping interior withing the bounds of the adorned element
            // so we have to track it's size to guarantee that...
            FrameworkElement fel = adornedElement as FrameworkElement;

            if (fel != null)
            {
                fel.SizeChanged += new SizeChangedEventHandler(AdornedElement_SizeChanged);
            }
        }