Silverlight 5 中 Canvas 的拖放功能
我正在 Silverlight 5 中开发一个项目,几个月前我已经在 WPF 中实现了该项目。我想“嗯,过几天我会把它移植过来......”。错了:)
对于我的问题: 我的窗口上有一个列表框和 2-3 个画布元素。列表框包含一些我想拖到画布上的字符串,并将其作为标签/文本框/面板或只是一个 UIElement 放置在那里。另外我想移动画布上的 UIElements 或将其移动到另一个画布。 在 WPF 中,我可以毫无问题地做到这一点。 过去 4 天我一直在寻找一个简单/好的解决方案,但我发现没有任何可用的解决方案。
是的,我知道 Silverlight Toolkit 有 DropTargets(ListBox、TreeView 等),但是是否可以编写自定义目标? CanvasDropTarget 或者类似的东西?或者是否可以使用PanelDragDropTarget来解决这样的问题?
提前致谢, 最好的问候
编辑:
我找到了一个线程,这似乎是我的解决方案的良好开端
所以,我找到了一个解决方案。我没想到这么简单。我只是用 PanelDragDropTarget 包围了 Canvas 并且它起作用了。
<toolkit:PanelDragDropTarget AllowDrop="True" AllowedSourceEffects="All" Height="251" HorizontalAlignment="Left" Margin="26,27,0,0" Name="panelDragDropTarget1" VerticalAlignment="Top" Width="302" Grid.Column="1">
<Canvas Name="canvas1" AllowDrop="True" Background="Green" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="249" Width="308"></Canvas>
</toolkit:PanelDragDropTarget>
对于事件:
panelDragDropTarget1.Drop += new Microsoft.Windows.DragEventHandler(panelDragDropTarget1_Drop);
panelDragDropTarget1.ItemDragStarting += new EventHandler<ItemDragEventArgs>(panelDragDropTarget1_ItemDragStarting);
你可以处理它。
i'm working on a project in Silverlight 5, which i have implemented in WPF some months ago. I thought "huh, i will port it in some days..". Wrong :)
To my problem:
I have a listbox and 2-3 canvas-elements on my Window. The listbox contains some string which i want to drag to a Canvas and drop it there as label / textbox / panel or simply a UIElement. Additionaly i want to move the UIElements on the Canvas or move it to another canvas.
In WPF i had no problem to do that.
I'm was searching the last 4 days for a simple / good solution, but i found nothing useable.
Yeah, i know that Silverlight Toolkit has DropTargets (ListBox, TreeView, etc) but is it possible to write a custom targt? A CanvasDropTarget or something like that? Or is it possible to use the PanelDragDropTarget for such a problem?
thanks in advance,
best regards
Edit:
I found a thread which seems to be a good start for my solution
So, i found a solution. I didn't thought thats that simple. I just surrounded a Canvas with a PanelDragDropTarget and it worked.
<toolkit:PanelDragDropTarget AllowDrop="True" AllowedSourceEffects="All" Height="251" HorizontalAlignment="Left" Margin="26,27,0,0" Name="panelDragDropTarget1" VerticalAlignment="Top" Width="302" Grid.Column="1">
<Canvas Name="canvas1" AllowDrop="True" Background="Green" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Height="249" Width="308"></Canvas>
</toolkit:PanelDragDropTarget>
and with the events:
panelDragDropTarget1.Drop += new Microsoft.Windows.DragEventHandler(panelDragDropTarget1_Drop);
panelDragDropTarget1.ItemDragStarting += new EventHandler<ItemDragEventArgs>(panelDragDropTarget1_ItemDragStarting);
you can handle it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论