{"id":5302,"date":"2017-09-06T20:10:18","date_gmt":"2017-09-06T20:10:18","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=5302"},"modified":"2017-09-06T20:10:18","modified_gmt":"2017-09-06T20:10:18","slug":"adventures-in-uwp-prism-more-unity-than-prism","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/adventures-in-uwp-prism-more-unity-than-prism\/","title":{"rendered":"Adventures in UWP \u2013 Prism (more Unity than Prism)"},"content":{"rendered":"<p>Prism is a well used framework in WPF and it&#8217;s also available in UWP. So let&#8217;s try it out. We&#8217;re going to start by looking at switching the default generated (blank) UWP application into one which uses Prism or more specifically Unity and Prism&#8217;s navigation functionality.<\/p>\n<ul>\n<li>Create a Blank UWP application<\/li>\n<li>From Nuget install the package Prism.Unity (I&#8217;m using v6.3.0)<\/li>\n<li>Edit App.xaml.cs and change the base class from Application to PrismUnityApplication (yes we&#8217;ll use Unity for this test), don&#8217;t forget to add <em>using Prism.Unity.Windows;<\/em><\/li>\n<li>Remove all generated code from App.xaml.cs except for the constructor<\/li>\n<li>Open App.xaml and change it from using Application to PrismApplication, for example\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;windows:PrismUnityApplication\r\n    x:Class=&quot;MathsTest.App&quot;\r\n    xmlns=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&quot;\r\n    xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&quot;\r\n    xmlns:local=&quot;using:MathsTest&quot;\r\n    xmlns:windows=&quot;using:Prism.Unity.Windows&quot;\r\n    RequestedTheme=&quot;Light&quot;&gt;\r\n\r\n&lt;\/windows:PrismUnityApplication&gt;\r\n<\/pre>\n<\/li>\n<li>Add the following bare bones method (yes it&#8217;s not handling possible startup states etc. as I wanted to reduce this code to the minimum)\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nprotected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)\r\n{\r\n   NavigationService.Navigate(&quot;Main&quot;, null);\r\n   return Task.FromResult(true);\r\n}\r\n<\/pre>\n<\/li>\n<li>By default the UWP project will have created a MainPage.xaml but Prism&#8217;s navigation code expects this to be in a Views folder, so create a Views folder in your solution and move MainPage.xaml into this Views folder.\n<p>If you see an exception along the lines of &#8220;The page name does not have an associated type in namespace, Parameter name: pageToken&#8221; then you&#8217;ve probably not got a view with the correct name within the Views folder. Don&#8217;t forget to update the XAML and the xaml.cs files to include Views in the name space, i.e. TestApp.Views.MainPage<\/li>\n<\/ul>\n<p>At this point we have UWP running from Prism. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prism is a well used framework in WPF and it&#8217;s also available in UWP. So let&#8217;s try it out. We&#8217;re going to start by looking at switching the default generated (blank) UWP application into one which uses Prism or more specifically Unity and Prism&#8217;s navigation functionality. Create a Blank UWP application From Nuget install the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[73,106],"tags":[],"class_list":["post-5302","post","type-post","status-publish","format-standard","hentry","category-prism","category-universal-app"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=5302"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5302\/revisions"}],"predecessor-version":[{"id":5358,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/5302\/revisions\/5358"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=5302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=5302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=5302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}