检测拖放文件在WPF?拖放、文件、WPF

2023-09-07 02:25:25 作者:亞麻色的讪笑

是否有可能有一个WPF窗口/元件检测从Windows资源管理器文件的drag'n'dropping在C#.net 3.5?我找到了解决方案的WinForms,但没有为WPF。

Is it possible to have a WPF window/element detect the drag'n'dropping of a file from windows explorer in C# .Net 3.5? I've found solutions for WinForms, but none for WPF.

推荐答案

不幸的是,文本框,RichTextBox中,并FlowDocument的观众永远纪念拖和拖放事件的处理,其中$ P $向上冒泡到你的处理器pvents他们。可以恢复拖和丢弃事件被截获这些控件以武力处理拖动和拖放事件(使用UIElement.AddHandler并设置handledEventsToo为true),并设置e.Handled假的处理程序。

Unfortunately, TextBox, RichTextBox, and FlowDocument viewers always mark drag-and-drop events as handled, which prevents them from bubbling up to your handlers. You can restore drag-and-drop events being intercepted by these controls by force-handling the drag-and-drop events (use UIElement.AddHandler and set handledEventsToo to true) and setting e.Handled to false in your handler.