为什么WPF Canvas不会掉线?

cor*_*vus 8 wpf drag-and-drop visual-studio-2008

我在主窗口中有以下XAML:

<Window x:Class="ImageViewer.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1" Height="398" Width="434">
   <Grid>
      <Canvas AllowDrop="True" />
   </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试将文件拖到窗口时,不允许删除.当Canvas更改为ListBox时,一切都很完美.

如何更改代码以允许删除画布?

jef*_*ora 24

默认情况下,Canvas没有背景,因此命中测试不会发现光标位于Canvas元素上方,而是冒泡到GridWindow不允许丢弃.将背景设置Transparent为如下,它应该工作:

<Window x:Class="ImageViewer.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1" Height="398" Width="434">
   <Grid>
      <Canvas AllowDrop="True" Background="Transparent" />
   </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)