Exemple #1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _canvas = GetTemplateChild <Canvas>(CanvasName);
            _image  = GetTemplateChild <Image>(ImageName);

            // Add manipulation event handlers
            _canvas.ManipulationMode =
                ManipulationModes.Scale | ManipulationModes.ScaleInertia |
                ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.TranslateInertia;
            _canvas.ManipulationStarting        += OnManipulationStarting;
            _canvas.ManipulationStarted         += OnManipulationStarted;
            _canvas.ManipulationDelta           += OnManipulationDelta;
            _canvas.ManipulationCompleted       += OnManipulationCompleted;
            _canvas.ManipulationInertiaStarting += OnManipulationInertiaStarting;

            // CAUTION: this needs to not happen in design mode, as it causes a problem there
            // Window.Current.CoreWindow.PointerWheelChanged += OnPointerWheelChanged;

            FrameworkElementExtensions.SetCursor(this, new CoreCursor(CoreCursorType.Arrow, 0));
            _canvas.PointerMoved += OnPointerMoved;

            _cropLeft = _cropRight = _cropTop = _cropBottom = 50;

            // Set image to a zero size until it's properly loaded
            // This handily avoids some crashes, and some visual issues
            SetWidthHeight(_image, 0, 0);

            _isTemplateApplied = true;

            Setup();
        }
Exemple #2
0
        private Point SetCursorForPosition(Point position)
        {
            DragMode dragMode = CalculateDragMode(position);

            CoreCursorType cursorType;

            if (dragMode == DragMode.Full)
            {
                cursorType = CoreCursorType.Hand;
            }
            else if (dragMode == DragMode.TopLeft || dragMode == DragMode.BottomRight)
            {
                cursorType = CoreCursorType.SizeNorthwestSoutheast;
            }
            else if (dragMode == DragMode.TopRight || dragMode == DragMode.BottomLeft)
            {
                cursorType = CoreCursorType.SizeNortheastSouthwest;
            }
            else if (dragMode == DragMode.Top || dragMode == DragMode.Bottom)
            {
                cursorType = CoreCursorType.SizeNorthSouth;
            }
            else if (dragMode == DragMode.Left || dragMode == DragMode.Right)
            {
                cursorType = CoreCursorType.SizeWestEast;
            }
            else
            {
                cursorType = CoreCursorType.Arrow;
            }

            FrameworkElementExtensions.SetCursor(this, new CoreCursor(cursorType, (uint)cursorType));
            return(position);
        }
        private void DetermineResizeCursor()
        {
            var effectiveResizeDirection =
                this.DetermineEffectiveResizeDirection();

            if (effectiveResizeDirection == GridResizeDirection.Columns)
            {
                FrameworkElementExtensions.SetCursor(this, new CoreCursor(CoreCursorType.SizeWestEast, 1));
            }
            else
            {
                FrameworkElementExtensions.SetCursor(this, new CoreCursor(CoreCursorType.SizeNorthSouth, 1));
            }
        }