为什么我无法将文件从资源管理器拖放到 FlowDocumentReader 以及如何修复它?

发布于 2024-08-07 18:23:38 字数 320 浏览 2 评论 0原文

我正在尝试实现一项功能,允许用户将文件拖到要在 FlowDocumentReader 中打开的应用程序中。

我的问题是,虽然我在 FlowDocumentReader 上设置了 AllowDrop=true,但光标不会更改为“放置到此处”图标,而是更改为“不允许放置”图标。 这种情况仅发生在 FlowDocumentReader 上,UI 的所有其他部分(窗口本身、其他控件)都按预期工作。 FlowDocumentReader 实际上接收事件,并且可以处理放置,但用户没有视觉指示表明他可以在此处释放鼠标。

我也无法通过设置 Cursor=Cursors.None 来隐藏“不允许放置”光标

I'm trying to implement a piece of functionality that will let the user to drag files into an application to be opened in the FlowDocumentReader.

My problem is that is though I have AllowDrop=true on the FlowDocumentReader, the cursor does not change to the "drop here" icon but changes instead to "drop is not allowed" icon.
This happens only to the FlowDocumentReader, all other parts og the UI (window itself, other controls) work as expected. The FlowDocumentReader actually receives the events, and it is possible to handle the drop, but the user does not have a visual indication that he can release the mouse here.

I also cannot hide the "drop is not allowed" cursor by setting Cursor=Cursors.None

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走就滚别墨迹 2024-08-14 18:23:38

需要处理 FlowDocument 中的 DragOver 事件以允许放置在此处。

xaml:

<!--
<FlowDocumentReader x:Name="fdr" Background="White">
    <FlowDocument x:Name="doc" AllowDrop="True" DragEnter="doc_DragOver" Drop="doc_Drop" Background="White"/>
    </FlowDocumentReader>
-->
<FlowDocumentReader x:Name="fdr" Background="White">
   <FlowDocument x:Name="doc" AllowDrop="True" DragOver="doc_DragOver" Drop="doc_Drop" Background="White"/>
</FlowDocumentReader>

背后代码:

private void doc_DragOver(object sender, DragEventArgs e)
{
    e.Effects = DragDropEffects.All;
    e.Handled = true;
}

private void doc_Drop(object sender, DragEventArgs e)
{
}

Need to handle DragOver event in FlowDocument to allow dropping here.

xaml:

<!--
<FlowDocumentReader x:Name="fdr" Background="White">
    <FlowDocument x:Name="doc" AllowDrop="True" DragEnter="doc_DragOver" Drop="doc_Drop" Background="White"/>
    </FlowDocumentReader>
-->
<FlowDocumentReader x:Name="fdr" Background="White">
   <FlowDocument x:Name="doc" AllowDrop="True" DragOver="doc_DragOver" Drop="doc_Drop" Background="White"/>
</FlowDocumentReader>

code behind:

private void doc_DragOver(object sender, DragEventArgs e)
{
    e.Effects = DragDropEffects.All;
    e.Handled = true;
}

private void doc_Drop(object sender, DragEventArgs e)
{
}
烧了回忆取暖 2024-08-14 18:23:38

我找不到任何直接的方法来解决这个问题,所以这就是我最终得到的结果:

  • 我在 FlowDocumentReader 的顶部放置了一个网格。该网格具有已售颜色、不透明度 0(透明)和 Visibility=Collapsed。该网格的目的是作为放置目标。
  • 当 FlowDocumentReader 中的 FlowDocument 收到 DragEnter 事件时,我将网格的可见性切换为可见。网格开始接收拖动事件,并且光标停留在“拖放此处”形式。
  • 当网格接收到 Drop 或 DragLeave 事件时,其可见性将转回 Collapsed 以允许 FlowDocument 接收鼠标事件

    
        
    
    <网格 x:名称=“dtg” Grid.Row=“1” 背景=“白色” 不透明度=“0”
        Drop="dtg_Drop" DragLeave="dtg_DragLeave" Visibility="Collapsed"/>
    

I couldn't find any direct way to solve this, so here is what I have ended up with:

  • I placed a grid on top of the FlowDocumentReader. This grid has a sold color, opacity of 0 (transparent) and Visibility=Collapsed. The purpose of this grid is to serve as a drop target.
  • When FlowDocument within the FlowDocumentReader received the DragEnter event, I switch the grid's visibility to Visible. The grid starts receiving drag events and the cursor stays in the "drop here" form.
  • When grid receives Drop or DragLeave events, its visibility is turned back to Collapsed to allow the FlowDocument receive mouse events

    <FlowDocumentReader x:Name="fdr" Grid.Row="1" Background="White">
        <FlowDocument x:Name="doc" DragEnter="doc_DragEnter" Background="White"/>
    </FlowDocumentReader>
    <Grid x:Name="dtg" Grid.Row="1" Background="White" Opacity="0"
        Drop="dtg_Drop" DragLeave="dtg_DragLeave" Visibility="Collapsed"/>
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文