Question

I just want to have the relative mouse / finger position in Silverlight Windows Phone App.

Using the original Silverlight Framework does not work because MouseMove does not update proper. 'MouseMove' event is firing very less instead of 'Manipulation' event. By using the DeltaManipulation event all works fast, but I am not able to calculate the position, relative to the device screen.

Example:

If user taps in the middle of the screen (Width/Height = 800/480), I want to see position 400,240. But ManipulationOrigin shows 0,0

Private Sub PageEditor_ManipulationDelta(sender As Object, e As ManipulationDeltaEventArgs) Handles Me.ManipulationDelta
    Call DragItem(e.ManipulationOrigin)' > e.ManipulationOrigin is 0,0 
End Sub
Was it helpful?

Solution

After tries of XNA and Silverlight methods, this one can show the Position of Mouse and it will show the position relative to any Framework Element too with high performance:

Private Touch As System.Windows.Input.Touch
Public Sub New()
    InitializeComponent()
    AddHandler System.Windows.Input.Touch.FrameReported, AddressOf Touch_FrameReported
End Sub


Private Sub Touch_FrameReported(sender As Object, e As TouchFrameEventArgs) 
    If Me.DragElement IsNot Nothing Then
        _MousePosition = e.GetPrimaryTouchPoint(Me.ucGameCanvas1).Position ' will return 400,240 as needed if user press in the middle of the screen
    End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top