为什么WPF Canvas不会下降? [英] Why doesn't WPF Canvas alow drop?

查看:137
本文介绍了为什么WPF Canvas不会下降?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在主窗口中有以下XAML:

I have the following XAML for the main window:

<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>

但是当我尝试将文件拖动到窗口时,不允许放下。当Canvas更改为ListBox时,一切都可以正常工作。

But when I try to drag a file to the window, drop is not allowed. When Canvas is changed to ListBox, everything works perfectly.

如何更改代码以允许下拉画布?

How can the code be changed to allow drop to canvas?

推荐答案

默认情况下, Canvas 没有任何背景,所以命中测试不会拾取光标在 Canvas 元素,而是冒泡到 Grid Window 不要放下将背景设置为透明,如下所示,它应该有效:

By default, Canvas has no background so hit-testing is not picking up that the cursor is over the Canvas element, but is instead bubbling up to the Grid or Window which don't allow drop. Set the background to Transparent as follows and it should work:

<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>

这篇关于为什么WPF Canvas不会下降?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆