silverlight实现页面缩放,拖动?解决办法
发布时间:2011-06-27 19:59:57 文章来源:www.iduyao.cn 采编人员:星星草
silverlight实现页面缩放,拖动?
请问如何实现?
------解决方案--------------------
<Grid x:Name="LayoutRoot" Background="White">
<Canvas x:Name="rootCanvas" Background="Gray" Margin="12,12,12,156">
<!-- You can drag this rectangle around the canvas. -->
<Rectangle
MouseLeftButtonDown="Handle_MouseDown"
MouseMove="Handle_MouseMove"
MouseLeftButtonUp="Handle_MouseUp"
Canvas.Left="30" Canvas.Top="30" Fill="Red"
Width="50" Height="50" />
</Grid>
Dim isMouseCaptured As Boolean
Dim mouseVerticalPosition As Double
Dim mouseHorizontalPosition As Double
Public Sub New()
InitializeComponent()
End Sub
Private Sub Handle_MouseDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
Dim item As Rectangle = sender
mouseVerticalPosition = e.GetPosition(Nothing).Y
mouseHorizontalPosition = e.GetPosition(Nothing).X
isMouseCaptured = True
item.CaptureMouse()
End Sub
Private Sub Handle_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim item As Rectangle = sender
If (isMouseCaptured) Then
' Calculate the current position of the object.
Dim deltaV As Double = e.GetPosition(Nothing).Y - mouseVerticalPosition
Dim deltaH As Double = e.GetPosition(Nothing).X - mouseHorizontalPosition
Dim newTop As Double = deltaV + item.GetValue(Canvas.TopProperty)
Dim newLeft As Double = deltaH + item.GetValue(Canvas.LeftProperty)
' Set new position of object.
item.SetValue(Canvas.TopProperty, newTop)
item.SetValue(Canvas.LeftProperty, newLeft)
' Update position global variables.
mouseVerticalPosition = e.GetPosition(Nothing).Y
mouseHorizontalPosition = e.GetPosition(Nothing).X
End If
End Sub
Private Sub Handle_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
Dim item As Rectangle = sender
isMouseCaptured = False
item.ReleaseMouseCapture()
mouseVerticalPosition = -1
mouseHorizontalPosition = -1
End Sub
------解决方案--------------------
你可以参考以下文章:
Silverlight实用窍门系列:51.Silverlight页面控件的放大缩小、Silverlight和Html控件的互相操作http://www.cnblogs.com/chengxingliang/archive/2011/08/03/2124838.html
Silverlight实用窍门系列:7.制作可拖动的自定义控件,获取拖拽后控件坐
http://www.cnblogs.com/chengxingliang/archive/2011/02/17/1956856.html
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
新手求助LineSeries折线的圆点怎么去掉
由于数据比较密集,LineSeries的圆点很大程度上影响了折线图的展示,请问可不可以设置式样把...
-
求教大家:如何继承SL5中的DrawingSurface?
自己写了一个MyDrawingSurface类,继承自DrawingSurface,只在原有基础上新增了几个属性而已...
-
[讨论]Silverlight5 RTM 只能在OOB模式下使用3D硬件加速?
来自:http://silverlight.bayprince.com/tutorials.php?tutorial=8
Silv...
-
LineSeries横轴名称重叠问题
LineSeries横轴名称多的时候,就会重叠,看不清楚,有设置让不重叠,省略一些名称
------解决方案---------...
-
Silverlight DataGrid依某列值決定字体顏色
比如:表里有三列:id,namd,age
我希望当age<18时,age数字的颜色为红色.
本人在网上查过...
-
新手问题,关于WPF的DataGrid控件列标题居中问题!
内容居中已经解决但是标题居中查过一些资料无果!网上有silverlight 4的DataGrid居...
-
serverlight 地图路径查询
就是在serverlight地图上创建两个点,实现最短路径的查询功能,不知道有发实现吗?
------解决方案--------...
-
Microsoft Expression Blend 4 的密钥谁有?
下载了一个Microsoft Expression Blend 4 可是要密钥 怎么办
------解决方案--------...
-
silverlight的输入框在win7平板电脑上不能被感知
最近用了个win7的平板电脑,普通页面如果有输入框,光标点击在上面,光标附件会出现一...
-
Win 8将Silverlight和.Net打入冷宫?
在D9大会上,微软演示了Windows 8如何为应用程序整合了一个以触摸操作为主的用户界面,这些应用...