WPF拖放和数据类型 [英] WPF drag and drop and data types

查看:66
本文介绍了WPF拖放和数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得所放置对象的类型?

How does one get the type of the dropped object? How can it be added it to a specific struct/list?

推荐答案

假设您控制拖动的开始(您正在而不是从其他应用程序中拖动),具体取决于类型。只需使源代码和目标代码匹配即可。在拖动中(通常是MouseMove或MouseDown处理程序):

Assuming you control the start of the drag (you're not dragging from another app), it's up to you what the type is. Just make the source and destination code match. In the drag (typically a MouseMove or MouseDown handler):

        var dragData = new DataObject(typeof(JobViewModel), job);
        DragDrop.DoDragDrop(element, dragData, DragDropEffects.Move);

开始拖动。然后在下拉菜单中(听起来您已经走到现在为止):

Begins the drag. And then in the drop (it sounds like you've gotten this far):

        var dataObj = e.Data as DataObject;
        var dragged = dataObj.GetData(typeof(JobViewModel)) as JobViewModel;

您也可以使用字符串而不是类型。

You can also use a String instead of a Type.

这篇关于WPF拖放和数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆