- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我真的很难在 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/
我正在尝试从 F# 编译代码以在 Silverlight 中使用。我编译: --noframework --cliroot "C:\program Files\Microsoft Silverligh
我正在为 Silverlight 安装一个编程环境并试图理顺需要安装的内容,感谢反馈: 在 http://silverlight.net/GetStarted ,第一点允许您安装“ Silverlig
Silverlight RIA 值得学习还是我应该坚持普通的 Silverlight? 背景: 我在 WPF 中做了几个小应用程序 我有 12 年的 VB6/WinForms 模型商业应用经验 我希望
我已经熟悉 Silverlight 编程,但没有任何 GIS 经验。 我作为 Silverlight 开发人员的角色只是显示现有的 GIS 数据。 如果你们有任何经验arcGIS silverligh
我需要在我的 Silverlight 应用程序中创建滚动选取框。选取框需要从右向左滚动。当它完成滚动时,它需要自动重新启动 诀窍是,我需要使用 ItemsControl,因为项目将在滚动时添加到列表中
Silverlight 导航模板在浏览器外运行时是否有效? 最佳答案 当然可以。 并且您可以使用 NavigationServices 函数来创建自定义的“后退”或“前进”按钮 很好的例子:Link
用户通过导航到给定的 URL 在他们的浏览器中启动 Silverlight 应用程序。 然后用户打开另一个浏览器并通过导航到相同的 URL 启动相同的 Silverlight 应用程序。 应用程序的第
Silverlight 4 程序集二进制文件是否与 Silverlight 5 兼容。SL4 程序集是否“在 SL5 运行时中运行”?如果兼容,是否100%兼容。您应该能够在您的 SL5 项目中使用第
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 9年前关闭
我正在寻找是否可以在可以在 application.resources 中设置然后在整个应用程序中使用的 Silverlight 控件中使用应用程序范围的字体。他们不需要指定有关字体的其他内容,例如粗
我正在使用Silverlight4。我想用一个可用字体列表填充组合框。我搜索过很多东西,找不到解决方法。似乎有很多死胡同。五月份曾提出过类似的问题,但没有合适的答案。 当然不是不可能吗? 最佳答案 如
我正在为 Silverlight 很好地实现弱事件模式以避免内存泄漏。 似乎有一些实现,但代码并非微不足道,很难知道哪个是正确的。我找不到微软的任何官方推荐。 如果可能的话,我追求简单的语法。 干杯。
Silverlight 应用程序是在您每次访问该站点时都会下载,还是会检查版本/大小信息并仅下载较新版本的文件? 最佳答案 Silverlight 2 在这方面没有什么特别的,我读过的最简洁的解释来自
我正在尝试在 silverlight 中使用样式触发器,如下所示:
我想尝试制作一个包含多个 Silverlight 画廊中的图片的 asp 网站。我想这样做的原因是我想要这样的东西: Text describing some places. Gallery with
WPF 3.5 有 PresentationTraceSources用于诊断和WPFPerf用于性能和数据绑定(bind)诊断。 Silverlight 是否有等效的工具/库? 最佳答案 尽管我已将
我有一个表示有向图的数据结构,我正在寻找一个好的 Silverlight 可视化,以允许我从一个节点导航到另一个节点,最好有一些漂亮的动画。 有没有人知道这种显示的任何好的 UI 控件或框架?甚至来自
我可以将byte []转换为图像: byte[] myByteArray = ...; // ByteArray to be converted MemoryStream ms = new Memo
我有多个Silverlight项目,希望使用相同的样式,配色方案和一些模板化对象。 我该如何完成? 最佳答案 一种实现方法是创建一个新的silverlight类库,该库将是您共享的主题/样式程序集,其
我正在尝试使用 SLLAUNCHER.EXE 启动已安装的 SL Out-of-Browser App。运行以下命令后,桌面上的 MyApp 启动图标就消失了。如果我在没有覆盖开关的情况下尝试它,则不
我是一名优秀的程序员,十分优秀!