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