silverlight之任意UI元素上启用拖放功能
2011-07-12 10:30
218 查看
function dragDropEnable(element) { //Attach three "private" event handlers contained inside this function element.AddEventListener("MouseLeftButtonDown",onMouseLeftButtonDown); element.AddEventListener("MouseMove",onMouseMove); element.AddEventListener("MouseLeftButtonUp",onMouseLeftButtonUp); var dragging=false; var lastPoint=null; function onMouseLeftButtonDown(sender,mouseEventArgs) { //Start the drag sender.CaptureMouse(); lastPoint = mouseEventArgs.GetPosition(null); dragging=true; } function onMouseMove(sender,mouseEventArgs) { if(dragging) { //Move the element and remember this position for next time var point=mouseEventArgs.GetPosition(null); sender["Canvas.Left"]+=point.X-lastPoint.X; sender["Canvas.Top"]+=point.Y-lastPoint.Y; lastPoint=point; } } function onMouseLeftButtonUp(sender,mouseEventArgs) { //Here is the "drop" part of drag-and-drop sender.ReleaseMouseCapture(); dragging=false; } }[/code]
把这段js脚本放到任何项目中,它都不会与现有函数或全局变量冲突
相关文章推荐
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能 (转)
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(四十五)制作精美的可任意拖放对象的物品栏及装备栏
- 设置silverlight启用剪贴板的功能
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(四十五)制作精美的可任意拖放对象的物品栏及装备栏
- WPF学习- AllowDrop 用户控件启用拖放功能
- Silverlight中按钮实现简单的拖放功能注意点
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- (5):Silverlight 2 实现简单的拖放功能
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(四十五)制作精美的可任意拖放对象的物品栏及装备栏
- (5):Silverlight 2 实现简单的拖放功能
- silverlight:类似iBaidu,iGoogle的拖放功能
- C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):(四十五)制作精美的可任意拖放对象的物品栏及装备栏
- 一步一步学Silverlight 2系列(5):实现简单的拖放功能
- Windows azure 下如何配置启用可扩展功能---Bginfo