开发者

How to AllowDrop only for specific types?

开发者 https://www.devze.com 2023-01-25 00:52 出处:网络
I use a LibraryBar to display some items that have a relationship. Since there are different relationships between items, I have multiple containers. As the default setting if is set AllowDrop to true

I use a LibraryBar to display some items that have a relationship. Since there are different relationships between items, I have multiple containers. As the default setting if is set AllowDrop to true for a LibraryBar, it is possible to drag all elements into the LibraryBar, and the items are added to the collection they are dropped.

Now I don't want that. I don't want that it is possible to drag a item from one LibraryBar to another. However I can't just set AllowDrop to false, because I want to drag some TagVisualizations into the LibraryBar.

So i defined in my method that handles DropEvents:

public void OnTargetDrop(object sender, SurfaceDragDropEventArgs e)
        {
            //only if TagVisualization
            if (e.Cursor.Data is Image)
            {
                ((sender as LibraryBar).Tag as ISourceFile).unexpand();
                e.Handled = true;
            }
            else
            {
                //TODO: cancel Drag&Drop
          开发者_如何学运维  }
        }

As you can see I only allow drops if the Cursor's Data is an Image (and therefore I now a TagVisualization). This works, it is no longer possible to drop an item from another LibraryBar into this LibraryBar. However the animation that is played if an item is dragged over an LibraryBar is still played. How can I also disable this animation for specific types?


Add an event handler for the DragCompleted event. Set handled equal to true for any types which you want to exclude. The DragCompletedEventArgs also have the Cursor.Data property.

0

精彩评论

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

关注公众号