<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://bloggingabout.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'WPF', 'Swipe', and 'Touch'</title><link>http://bloggingabout.net/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=WPF,Swipe,Touch&amp;orTags=0</link><description>Search results matching tags 'WPF', 'Swipe', and 'Touch'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Adding Swipe functionality to WPF Applications</title><link>http://bloggingabout.net/blogs/egiardina/archive/2010/11/23/adding-swipe-functionality-to-wpf-applications.aspx</link><pubDate>Tue, 23 Nov 2010 19:52:00 GMT</pubDate><guid isPermaLink="false">813b6dfd-644e-4573-a816-eebab56ba0d0:484335</guid><dc:creator>Richthofen</dc:creator><description>&lt;p&gt;As part of a kiosk application written in WPF, the client wanted &amp;#39;Swipe&amp;#39;-like functionality similar to many touch-enabled smartphones. It&amp;#39;s actually not that hard in .NET 4 and WPF.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;First, add a property to your page/control that keeps track of the Touch that the user has initiated to start the swipe event:&lt;/p&gt;
&lt;p&gt;protected TouchPoint TouchStart;&lt;/p&gt;
&lt;p&gt;In the codebehind of the Page or Control you&amp;#39;re building, add the following handlers:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;public BasePage()&lt;/p&gt;
&lt;p&gt;&lt;span&gt;		&lt;/span&gt;{&lt;/p&gt;
&lt;p&gt;&lt;span&gt;			&lt;/span&gt;this.TouchDown += new EventHandler&amp;lt;TouchEventArgs&amp;gt;(BasePage_TouchDown);&lt;/p&gt;
&lt;p&gt;&lt;span&gt;			&lt;/span&gt;this.TouchMove += new EventHandler&amp;lt;TouchEventArgs&amp;gt;(BasePage_TouchMove); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;		&lt;/span&gt;}&lt;/p&gt;
&lt;p&gt;These handlers help detect when a user has pressed down and moved his/her finger over your page or control.&lt;/p&gt;
&lt;p&gt;Next, handle the initial Touch event that triggers the swipe:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;void BasePage_TouchDown(object sender, TouchEventArgs e)&lt;/p&gt;
&lt;p&gt;{&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TouchStart = e.GetTouchPoint(this);&amp;nbsp;}&lt;/p&gt;
&lt;p&gt;Finally, handle the movement aspect of the touch. If the movement exceeds some threshhold; then we consider it a swipe and execute whatever code we want to do (Navigation, animation, etc)&lt;/p&gt;
&lt;p&gt;Here, &amp;#39;AlreadySwiped&amp;#39; is just a flag property so we don&amp;#39;t execute the same task multiple times if the swipe exceeds our threshhold more than once. You are responsible for resetting it after you do your on-swiped code.&amp;nbsp;Also, I used 200 pixels as the swipe threshhold, but you may want a bigger/smaller value. You may also want to consider percentages of X here instead of actual pixels.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;void BasePage_TouchMove(object sender, TouchEventArgs e)&lt;/p&gt;
&lt;p&gt;&lt;span&gt;		&lt;/span&gt;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (!AlreadySwiped)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var Touch = e.GetTouchPoint(this);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//right now a swipe is 200 pixels&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Swipe Left&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (TouchStart != null &amp;amp;&amp;amp; Touch.Position.X &amp;gt; (TouchStart.Position.X + 200))&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RunMyCustomCode();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AlreadySwiped = true;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Swipe Right&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (TouchStart != null &amp;amp;&amp;amp; Touch.Position.X &amp;lt; (TouchStart.Position.X - 200))&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;RunMyCustomCodeSwipeRight();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AlreadySwiped = true;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.Handled = true;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;		&lt;/span&gt;}&lt;/p&gt;
&lt;/p&gt;
&lt;p&gt;This should be straightforward but send me a message if you have any questions.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>