UPDATE: You should be using the Window to receive events. See my updated post for details.
Yes, it can be done easily, including inertia. It does require the Windows 7 Multitouch .NET Interop Sample Library
First, create a class that inherits from scrollviewer.
Code Snippet
- Public Class MultiTouchScollViewer
- Inherits ScrollViewer
-
- End Class
Then you add references to Windows7.Multitouch.dll and Windows7.Multitouch.Wpf.dll.
Then modify the MultiTouchScrollViewer like so:
Code Snippet
- Imports System.Windows
- Imports System.Windows.Controls
-
- Public Class MultiTouchScrollViewer
- Inherits ScrollViewer
-
- Private GestureHandler As Windows7.Multitouch.GestureHandler
-
- Public Sub New()
- AddHandler MyBase.Loaded, New RoutedEventHandler(AddressOf Me.MultiTouchScollViewer_Loaded)
- Me.GestureHandler = Nothing
- End Sub
-
- Private Sub MultiTouchScollViewer_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
- If Windows7.Multitouch.TouchHandler.DigitizerCapabilities.IsMultiTouchReady Then
- GestureHandler = Windows7.Multitouch.WPF.Factory.CreateGestureHandler(System.Windows.Window.GetWindow(Me))
- AddHandler GestureHandler.Pan, AddressOf Me.GestureHandler_Pan
- End If
- End Sub
-
- Private Sub GestureHandler_Pan(ByVal sender As Object, ByVal e As Windows7.Multitouch.GestureEventArgs)
- Dim s As System.Drawing.Size = e.PanTranslation
-
- Me.ScrollToVerticalOffset(Me.VerticalOffset - s.Height)
- End Sub
-
- End Class
Download the VB.NET code here
Download the C# code here
NOTE: It does require hit testing if using multiple scrollviewers in the same window.
Currently rated 5.0 by 1 people
- Currently 5/5 Stars.
- 1
- 2
- 3
- 4
- 5