Example detecting swipes in 1 axis

You can apply this to any page element, a text box for instance. In this example we use the canvas, but you don’t have to.

In your .xaml file
        <Canvas x:Name="OurCanvas" Width="800" Height="1513"
                ManipulationMode="TranslateX, TranslateInertia, System"
                ManipulationDelta="SwipeToScroll_ManipulationDelta"
                ManipulationCompleted="SwipeToScroll_ManipulationCompleted"
                >
In your .cs code
		private void SwipeToScroll_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
		{
			if (e.IsInertial)
			{
				var SwipedDistance = e.Cumulative.Translation.X;

				//Check for min swipe distance
				if (Math.Abs(SwipedDistance ) <= 10)
					return;

				if (SwipedDistance  > 0)
				{
					//Scroll to top
					PageScrollViewer.ChangeView(0, 0, 1);       //horizontalOffset, verticalOffset, zoomFactor
				}
				else
				{
					//Scroll to bottom
					PageScrollViewer.ChangeView(0, PageScrollViewer.ScrollableHeight, 1);
				}
			}
		}

		private void SwipeToScroll_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
		{
			//Remove this event if you don't want it...
		} 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *