gpt4 book ai didi

wpf - 为什么 WPF Canvas 不允许掉落?

转载 作者:行者123 更新时间:2023-12-02 20:20:04 26 4
gpt4 key购买 nike

我的主窗口有以下 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>

但是当我尝试将文件拖到窗口时,不允许放置。当 Canvas 更改为 ListBox 时,一切正常。

如何更改代码以允许拖放到 Canvas 上?

最佳答案

默认情况下,Canvas 没有背景,因此 HitTest 不会检测到光标位于 Canvas 元素上,而是冒泡到 >GridWindow 不允许放置。将背景设置为透明,如下所示,它应该可以工作:

<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 - 为什么 WPF Canvas 不允许掉落?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7762957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com