{"id":221,"date":"2015-09-29T18:06:55","date_gmt":"2015-09-29T18:06:55","guid":{"rendered":"http:\/\/nofl.biz\/blog\/?p=221"},"modified":"2015-09-29T18:06:55","modified_gmt":"2015-09-29T18:06:55","slug":"visual-studio-2015-first-app-for-windows-8-110","status":"publish","type":"post","link":"https:\/\/beneford.com\/Blog\/index.php\/2015\/09\/29\/visual-studio-2015-first-app-for-windows-8-110\/","title":{"rendered":"Visual studio 2015 &#8211; First App for Windows 8.1\/10"},"content":{"rendered":"<p>Gone are the days when you could pick up a copy of Delphi, drag a few widgets onto a form and have the beginnings of an application. Right now, I&#8217;m wrestling with creating a Windows app that will run on both phone and tablet (one app, two platforms). This post is an attempt to write down the steps I&#8217;m taking to create the skeleton of the app.<\/p>\n<h3>The requirement<\/h3>\n<p>The App will have several pages and you can swap between the pages by swiping left or right. The content of these pages is not important, so in this trial app, it will just be some plain text.<\/p>\n<p>I&#8217;m using Visual Studio 2015, writing in C# and initially targeting Windows 8.1.<\/p>\n<h3>Beginning<\/h3>\n<p>Create a solution, and a skeleton app: C#\\Windows\\Windows 8\\Universal &#8211;&gt; Blank App<br \/>\nThis creates two projects within the solution.<\/p>\n<p>If you want the template navigation (forward and back pages), you can follow (eg) <a href=\"http:\/\/mtaulty.com\/CommunityServer\/blogs\/mike_taultys_blog\/archive\/2014\/05\/23\/windows-phone-8-1-frame-page-navigationhelper-suspensionmanager.aspx\" target=\"_blank\" rel=\"noopener\">Mike Taulty&#8217;s blog post<\/a>. to change the MainPages from &#8216;Blank&#8217; to &#8216;Basic&#8217;\u00a0pages (delete the MainPage and create a Basic Page called MainPage). This gives a simple way to change pages by calling:<\/p>\n<pre> Frame.Navigate(typeof(TargetPage),\"thisPageName\");<\/pre>\n<p>For &#8216;swipe&#8217; navigation, we need to use Gestures, and the application framework support these &#8216;out of the box&#8217;.<\/p>\n<p>We have to catch the ManipulationStarted and ManipulationCompleted events. To do this:<\/p>\n<ul>\n<li>name the outermost gird object: P1Grid<\/li>\n<li>double click on the event: ManipulationStarted and code it as:<\/li>\n<\/ul>\n<pre>private void P1Grid_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)\n{\n     startX = e.Position.X;\n}\n<\/pre>\n<ul>\n<li>double click on the event: ManipulationCompleted. In this example,\u00a0startX\u00a0&gt; e.Position.X means swipe\u00a0right to left. use &lt; instead to swipe left to right:<\/li>\n<\/ul>\n<pre>private void P1Grid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)\n{\n\u00a0\u00a0\u00a0 if (startX &gt; e.Position.X)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Frame.Navigate(typeof(SecondPage), this.pageTitle.Text);\n}<\/pre>\n<ul>\n<li>we also need to define a variable:<\/li>\n<\/ul>\n<pre>private double startX;<\/pre>\n<ul>\n<li>finally we need to change the Manipulation Mode of P1Grid to TranslateX.<\/li>\n<\/ul>\n<p>Now, running the app lets you swipe from right to left to change the page.<\/p>\n<h3>Visual Feedback<\/h3>\n<p>Users like some feedback when they&#8217;re doing something like swiping left\/right, and we can add an effect where the showing page is squashed in the direction of the swipe. The XAML objects have transformation built in that do what we want.<\/p>\n<ul>\n<li>We need to modify the xaml code to give object names for the transformation controls. The following goes inside\u00a0definition of P2Grid:<\/li>\n<\/ul>\n<pre>&lt;Grid.Projection&gt;\n\u00a0\u00a0\u00a0 &lt;PlaneProjection x:Name=\"P1Projection\" GlobalOffsetX=\"0\"\/&gt;\n&lt;\/Grid.Projection&gt;\n&lt;Grid.RenderTransform&gt;\n\u00a0\u00a0\u00a0 &lt;CompositeTransform x:Name=\"P1Transform\" ScaleX=\"1\"\/&gt;\n&lt;\/Grid.RenderTransform&gt;<\/pre>\n<ul>\n<li>then we add an event handler for ManipulationDelta. We calculate how much to squash and then set the transform to both squash and then offset P1Grid:<\/li>\n<\/ul>\n<pre>private void P1Grid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)\n{\n\u00a0\u00a0 double squash = (P1Grid.RenderSize.Width - (startX - e.Position.X) \/ 4) \/ P1Grid.RenderSize.Width;\n\u00a0\u00a0\u00a0 if (squash &gt;= 1)\n\u00a0\u00a0\u00a0 {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 P1Projection.GlobalOffsetX = 0;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 P1Transform.ScaleX = 1;\n\u00a0\u00a0\u00a0 }\n\u00a0\u00a0\u00a0 else\n\u00a0\u00a0\u00a0 {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 P1Projection.GlobalOffsetX = P1Grid.RenderSize.Width * (1 - 1\/squash);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 P1Transform.ScaleX = 1\/squash;\n\/\/ or to animate in the opposite direction:\n\/\/\tP1Projection.GlobalOffsetX = P1Grid.RenderSize.Width * (squash-1);\n\/\/\tP1Transform.ScaleX = squash;\n\u00a0\u00a0\u00a0 }\n}<\/pre>\n<ul>\n<li>Finally, we need to reset the transformation when the swipe has finished. We add two lines to the ManipulationCompleted code:<\/li>\n<\/ul>\n<pre>P1Projection.GlobalOffsetX = 0;\nP1Transform.ScaleX = 1;<\/pre>\n<p>For two pages moving back and forth, or for more pages, just combine the two directions of swiping.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gone are the days when you could pick up a copy of Delphi, drag a few widgets onto a form and have the beginnings of an application. Right now, I&#8217;m wrestling with creating a Windows app that will run on both phone and tablet (one app, two platforms). This post is an attempt to write [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,6],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-visual-studio","category-windows-development-2"],"_links":{"self":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":0,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"wp:attachment":[{"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/beneford.com\/Blog\/index.php\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}