gpt4 book ai didi

Silverlight DragDrop.DoDragDrop()

转载 作者:行者123 更新时间:2023-12-02 21:49:52 25 4
gpt4 key购买 nike

我真的很难在 Silverlight 4 中获得一个简单的拖放示例。

这是我所拥有的:

XAML

<UserControl x:Class="TestDragDrop.MainPage" Width="350" Height="200"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="White">
<Rectangle Margin="50,50,200,50" Fill="Orange" MouseLeftButtonDown="r1_MouseLeftButtonDown" />
<Rectangle Margin="200,50,50,50" Fill="Orange" AllowDrop="true" Drop="r2_Drop" />
</Grid>
</UserControl>

代码隐藏

public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}

private void r1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
DragDrop.DoDragDrop((Rectangle)sender, "test data", DragDropEffects.All, DragDropKeyStates.LeftMouseButton);
}

private void r2_Drop(object sender, System.Windows.DragEventArgs e)
{
MessageBox.Show("Drop: " + e.Data.ToString());
}
}

DragDrop.DragDropCompleted 事件确实会触发,但发送者参数始终为 null,并且事件参数并不能真正帮助我找到有关该事件的更多信息。

我还尝试使用自定义控件实现 IAcceptDrop,但没有成功。

此外,当我开始拖动操作时,我没有任何视觉反馈表明发生了某些事情(光标或任何东西都没有变化)。有什么问题吗?

我发现的所有示例都使用 DragDropTargets。是我为要使用的特定类型的控件实现 DragDropTarget 的唯一方法吗?

最佳答案

Silverlight 4 的拖放功能针对单一场景:将文件从计算机拖到 Silverlight 应用程序上。除此之外,您还需要使用 Toolkit 的 DragDropTarget 控件。 Tim Heuer 对拖放功能的描述: http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx

For some scenarios, you may have wanted to be able to drag a file from your desktop or file explorer on to your Silverlight application. By enabling the AllowDrop attribute on UIElement in this release, you can now accommodate those scenarios.

换句话说,他们并不打算让您能够在代码中实际创建自己的拖动操作。

此 URL 中的大多数(如果不是全部)“限制”部分仍然适用于 SL4 RTW: http://www.ningzhang.org/2009/11/28/silverlight-drag-and-drop-api/

  • there is no drop source support (QueryContinueDrag & GiveFeedback).
  • there is no DragDropEffects or DragDropKeyStates in DragEventArgs.
  • there is no visual for the dragged object or DragDropEffects.
  • only file drag and drop is supported: all drop target events fire only when files are being dragged and dropped. IDataObject, DataObject and DragEventArgs.Data support only one format: “FileDrop”, and the data is of type FileInfo[].
  • most of IDataObject methods throw NotImplementedException.

关于Silverlight DragDrop.DoDragDrop(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3868921/

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