Esempio n. 1
0
        private void AssociatedObject_GiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
            if (!IsDropPreviewEnabled)
            {
                return;
            }

            if (_cursorWindow == null)
            {
                if (e.Source is FrameworkElement element && element != null)
                {
                    var rtb            = WPFHelper.GetRenderTargetBitmap(element);
                    var shadowAreaSize = (double)AssociatedObject.FindResource("DragWindowShadowAreaSize");
                    _cursorWindow = new DragImage()
                    {
                        Title  = $"{AppSettings.AppTitle} cursor",
                        Width  = rtb.Width + shadowAreaSize * 2d,
                        Height = rtb.Height + shadowAreaSize * 2d
                    };
                    _cursorWindowXHotSpot        = -shadowAreaSize / 2d + 2d; // TODO: 2d gap could depends on system cursor size
                    _cursorWindowYHotSpot        = -shadowAreaSize / 2d + 2d;
                    _cursorWindow.IMG.Source     = rtb;
                    _cursorWindow.BackImg.Source = WPFHelper.GetImageMask(rtb);
                }
            }

            var p = new NativeTypes.POINT();

            GetCursorPos(ref p);

            if (_cursorWindow != null)
            {
                var x = p.X - _cursorWindow.ActualWidth - _cursorWindowXHotSpot;
                var y = p.Y - _cursorWindow.ActualHeight - _cursorWindowYHotSpot;

                _cursorWindow.SetPos(x, y, (IntPtr)SpecialWindowHandles.HWND_TOP);

                if (!_cursorWindow.IsVisible)
                {
                    _cursorWindow.Show();
                }
            }

            if (CanDropOnDesktop && CheckIsOverDesktop(p.X, p.Y))
            {
                e.UseDefaultCursors = false;
                Mouse.SetCursor(Cursors.Hand);
                e.Handled = true;
            }
        }