您的位置:首页 > 其它

Silverlight不响应鼠标实现拖动效果

2011-12-11 15:57 316 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Expression.Interactivity.Layout;

namespace SlAndHtml
{
public partial class SilverlightControl1 : UserControl
{
public SilverlightControl1()
{
InitializeComponent();

MouseDragElementBehavior mdeb = new MouseDragElementBehavior();
mdeb.ConstrainToParentBounds = true;   //设置不越界
FrameworkElement element = image1;     // image1 为你移动的控件
Interaction.GetBehaviors(element).Add(mdeb);

}
}
}


看看网上大家都在自己处理鼠标事件实现在Silverlight下面的拖动其实系统已经集成在里面了。需要大家安装Microsoft Expression Blend。

添加引用Microsoft.Expression.Interactions.dll

路径在

Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries\Microsoft.Expression.Interactions.dll

添加引用System.Windows.Interactivity.dll

路径在

Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries\System.Windows.Interactivity.dll

拖动代码实现

注意button是不能用于拖动的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: