开发者

WPF equivalent of Control.CursorChanged event

开发者 https://www.devze.com 2023-04-01 17:46 出处:网络
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

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消