如何知道您是否在 WPF 中进行拖动的同一个应用程序实例中进行拖放?
标题几乎解释了我的问题:
我现在正在处理拖拽和拖拽。放入我的应用程序中。我可以同时运行应用程序的多个实例,并且可以毫无问题地从一个实例拖动到另一个实例。
现在,我想知道我是否是拖拽者。删除“内部”(即:删除发生在与拖动相同的实例中)或“外部”(相反)
我走了这么远:我需要向我的拖动数据添加一个唯一的ID(类似于PUID)来标识我正在拖动的应用程序。然后我可以将这个 id 与我本地的 id 进行比较,看看是否相同。
我在拖动数据中传输此类信息没有问题,问题更多的是找到这个 UId。
我一直在考虑使用 Process.GetCurrentProcess().MainWindowHandle; ,但我不确定这是否是一个好主意。
我必须采取哪些选择才能使这项工作成功?
the title pretty much explains my issue:
I am right now taking care of drag & drop in my app. I can have many instances of my app running at the same time, and I can drag from one instance to the other without trouble.
Now, I would like to know if I'm drag & dropping "internally" (i.e: the drop occurs in the same instance as the drag) or "externally" (the opposite)
I went this far: I need to add to my dragged data a unique ID (something like a PUID) that identifies the app where I'm making the drag. Then I can just compare this id to the one I have locally on the drop and see if it is the same.
I have no problem transferring such info in my drag Data, the issue is more to find this UId.
I have been thinking using the Process.GetCurrentProcess().MainWindowHandle;
but I'm not sure if this is a good idea.
What option(s) do I have to make this work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会简单地创建一个只读 Guid,在您启动应用程序时对其进行设置。
您可以将其放在主要逻辑所在的位置(MainWindow 或 ViewModel)。
这是一个片段:
I would simply create a readonly Guid that gets set when you start your app.
You can put this wherever your main logic lives (MainWindow or ViewModel).
Here is a snippet:
DnD 很像一种 UI 活动,而不是内部活动。
我会区分两个上下文:删除文件和删除某些对象(例如 VS 设计器)。在第一种情况下根本没有问题,因为从哪里提取数据并不重要。在第二种情况下,您应该知道选择了什么对象。例如,您有一个包含许多项目(例如字母字符)的列表框,一旦用户 DnD 任何这些项目,内部操作就是对所选对象的简单引用。通过从另一个应用程序提取数据,您将无法找到您的对象,因为来源不同。
对于结构或字符串,您可以按照您正确的建议用 GUID 包装它们。
The D-n-D is much like an UI activity, than an internal one.
I would distinguish two contexts: dropping a file, and dropping some object (e.g. VS designer). In the first context there's no problem at all, because it doesn't matter where you pull the data. In the second case, you should know what object has been chosen. For instance, you have a listbox with many items (e.g. the alphabet chars), once the user D-n-D any of those items, the internal operation is a simple reference to the selected object. By pulling the data from another app, you won't be able to find your object, because the source is different.
In case of structs or strings, you may wrap them with a GUID, as you correctly proposed.