WPF 相当于 Control.CursorChanged 事件

发布于 2024-12-02 16:37:16 字数 873 浏览 0 评论 0原文

当我在 wpf 列表视图中拖动鼠标时,我试图在某个点更改鼠标光标。然而,当我设置鼠标时,它很快就会被其他东西覆盖,并变回拖动光标。

我不确定光标的变化来自哪里,它肯定不是来自我的代码,所以它必须是系统的。如果是系统,那么我必须拦截光标更改事件,并处理该事件以使光标显示我想要的内容,对吗?

那么是否有与此 Control.CursorChanged 事件等效的 WPF?或者也许还有其他方法来解决这个问题?

编辑:

这是我的代码的一部分,

    private void SetDragCursor()
    {
        if (_badDragLoc)
        {
            Mouse.OverrideCursor = Cursors.No;
        }
        else
        {
            Mouse.OverrideCursor = Cursors.Arrow;
        }
    }
    private void listView_DragOver(object sender, DragEventArgs e)
    {
        if (at a bad drag location)
        {
            _badDragLoc = true;
            SetDragCursor();
        }
    }

我还有一个拖动离开事件处理程序,其中也有 SetDragCursor() 方法。当我在调试器中逐步浏览每一行代码时,鼠标在进入拖动离开处理程序后立即从无光标变成拖动光标。这就是为什么我认为它必须是系统。

如果确实是系统,那么如果我可以捕获事件触发,我就可以自己处理这些事件而不让它冒泡。

谢谢你!

I am trying to change my mouse cursor at certain point when I'm dragging my mouse around in a wpf listview. However, when I set my mouse, it quickly gets overridden by something else, and get changed back to the drag cursor.

I am not sure where the cursor change comes from, it is certainly not from my code, so it has to be system. If it is system, then I have to intercept the event for cursor change, and handle the event in order for the cursor to show what I want right?

So is there a WPF equivalent of this Control.CursorChanged event? Or perhaps there's some other way to approach this problem?

Edit:

here's part of my code

    private void SetDragCursor()
    {
        if (_badDragLoc)
        {
            Mouse.OverrideCursor = Cursors.No;
        }
        else
        {
            Mouse.OverrideCursor = Cursors.Arrow;
        }
    }
    private void listView_DragOver(object sender, DragEventArgs e)
    {
        if (at a bad drag location)
        {
            _badDragLoc = true;
            SetDragCursor();
        }
    }

I also have a drag leave event handler, in which I also have the SetDragCursor() method as well. When I step by step go through each line of code in debugger, the mouse turned into the drag cursor from the no cursor right after it enters the drag leave handler. Which is why I think it has to be the system.

If it indeed is the system, then if I can capture the event firing, I can then handle those event myself and not let it bubble through.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷遇一生 2024-12-09 16:37:16

只是不是这样工作的,在 DragOver 事件期间设置光标的方法如下:

void listView__DragOver(object sender, DragEventArgs e)
     {
         if (!e.Data.GetDataPresent("Images"))
         {
             e.Effects = DragDropEffects.None;
             e.Handled = true;
         }
     }

根据您分配给 e.Effects 的 DragDropEffects 枚举值,鼠标将更改光标。

不要调用Mouse.OverrideCursor,因为这不是正确的方法。

Just does not work like that, the way to set the cursor during a DragOver event is the following:

void listView__DragOver(object sender, DragEventArgs e)
     {
         if (!e.Data.GetDataPresent("Images"))
         {
             e.Effects = DragDropEffects.None;
             e.Handled = true;
         }
     }

depending on the value of DragDropEffects enum you assign to e.Effects the mouse will change cursor.

do not call Mouse.OverrideCursor because is not the right way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文