Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
让拖放在WPF中工作,WPF已经在Windows窗体中工作_Wpf_Com_Interop_Drag And Drop - Fatal编程技术网

让拖放在WPF中工作,WPF已经在Windows窗体中工作

让拖放在WPF中工作,WPF已经在Windows窗体中工作,wpf,com,interop,drag-and-drop,Wpf,Com,Interop,Drag And Drop,我试图从一个COM API中使用这个函数,它使窗口能够像从另一个应用程序接收拖放一样接收拖放 它在Windows窗体和works中非常简单: public void EnableDropSupport(System.Windows.Forms.Form form) { IntPtr hwnd = form.Handle; _comAPI.RegisterDropWindow((int)hwnd); } 但我有一个WPF窗口,它不工作,我不明白为什么。我尝试了以下方法: public

我试图从一个COM API中使用这个函数,它使窗口能够像从另一个应用程序接收拖放一样接收拖放

它在Windows窗体和works中非常简单:

public void EnableDropSupport(System.Windows.Forms.Form form)
{
   IntPtr hwnd = form.Handle;
   _comAPI.RegisterDropWindow((int)hwnd);
}
但我有一个WPF窗口,它不工作,我不明白为什么。我尝试了以下方法:

public void EnableDropSupport(System.Windows.Window window)
{
   window.AllowDrop = true;
   WindowInteropHelper windowInteropHelper = new WindowInteropHelper(window);
   IntPtr hwnd = windowInteropHelper.Handle;
   _comAPI.RegisterDropWindow((int)hwnd);
}
最后两行基本相同,但在WPF中不起作用。当

window.AllowDrop=true

将使其看起来好像将接受丢弃,但不会引发该COM API的丢弃事件


我遗漏了什么或者有人能帮我吗?

这是帕维尔·米纳耶夫的回答,他将其作为对正确问题的评论发布:


WPF上没有遗漏任何内容 事情的另一面。很可能是 问题在于RegisterDropWindow


为什么你甚至需要任何特殊的COM函数呢?您应该能够使用AllowDrop和关联的WPF DnD事件处理所有DnD场景。此外,还不清楚RegisterDropWindow实际在做什么。就我所见,您的代码没有任何问题,但可能是RegisterDropWindow代码在某种程度上是WinForms特定的,或者至少不是WPF友好的。RegisterDropWindow以某种方式启用了窗口上的拖放功能。我不能使用WPF的拖放事件,因为我需要从COM API响应拖放事件。我希望这不是WinForms特有的,这就是为什么我想知道我是否做错了什么。你没有遗漏WPF方面的任何东西。最有可能的问题是RegisterDropWindow。