1

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

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

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

4

2 回答 2

3

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

xml:

<!--
<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)
{
}
于 2010-01-11T06:43:35.633 回答
0

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

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

    <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"/>
    
于 2009-10-20T15:56:30.543 回答