{"id":22890,"date":"2015-11-23T10:50:06","date_gmt":"2015-11-23T18:50:06","guid":{"rendered":"https:\/\/blog.xamarin.com\/?p=22890"},"modified":"2015-11-23T10:50:06","modified_gmt":"2015-11-23T18:50:06","slug":"getting-started-with-xamarin-forms-windows-10-preview","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/getting-started-with-xamarin-forms-windows-10-preview\/","title":{"rendered":"Getting Started with Xamarin.Forms 2.0&#8217;s Windows 10 Preview"},"content":{"rendered":"<p>\t\t\t\tWith the <a href=\"https:\/\/blog.xamarin.com\/introducing-xamarin-4\/\">release of Xamarin 4<\/a> came Xamarin.Forms 2.0, introducing new features and optimizations to help you build great native cross-platform mobile apps. In addition to ListView caching strategies, pinch gestures, and new properties came the first public preview of Xamarin.Forms for Windows 10 (UWP) applications. While Xamarin.Forms already supports Windows Phone and Store targets, Windows 10 introduces an Universal Windows project that can target both desktop and phone platforms, allowing you to easily target even more devices.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22922\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/promo-1024x597.png\" alt=\"promo\" width=\"800\" \/><\/p>\n<h2>Getting Started<\/h2>\n<p>Before you begin creating Universal Windows 10 apps with Xamarin.Forms, there are a few prerequisites that need to be installed.<\/p>\n<ul>\n<li>Windows 10<\/li>\n<li><a href=\"https:\/\/www.visualstudio.com\/vs-2015-product-editions\">Visual Studio 2015<\/a><\/li>\n<li><a href=\"https:\/\/dev.windows.com\/en-us\/downloads\/windows-10-sdk\">Universal Windows Developer Tools<\/a><\/li>\n<\/ul>\n<p>Once you have everything installed, it is time to get your Xamarin.Forms project ready. Xamarin.Forms 2.0 not only adds preview support for Windows 10 apps, but also add a plethora of additional features, optimizations, and awesome for your mobile apps. To get started, head over to the NuGet Package Manager in Visual Studio.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22910\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Manage-NuGet-Packages-1024x592.png\" alt=\"Manage NuGet Packages\" width=\"600\" \/><\/p>\n<p>Select the &#8220;Upgrade available&#8221; filter and update all of your NuGets to Xamarin.Forms 2.0.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22909\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/UpgradeNuGets-1024x609.png\" alt=\"UpgradeNuGets\" width=\"600\" \/><\/p>\n<p><em>Note<\/em>: Visual Studio may prompt to be restarted after this step.<\/p>\n<h2>Adding the Universal Windows App<\/h2>\n<p>Once all your NuGets are up to date, it is time to add a Blank Universal Windows project to your Xamarin.Forms solution. This can be found under Add New Project -&gt; Windows -&gt; Universal -&gt; Blank App.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22911\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/UWP-Project-Template-1024x207.png\" alt=\"UWP Project Template\" width=\"600\" \/><\/p>\n<h3>Add NuGets &amp; PCL\/Shared Project Reference<\/h3>\n<p>When you create a new Xamarin.Forms project, all of the references and NuGet packages are automatically added for you. However, for existing Xamarin.Forms projects that want to target UWP as well, you must add them in manually. First, add the Xamarin.Forms project. Right click on the solution and find &#8220;Manage NuGet Packages&#8230;&#8221;, and from the filter dropdown select &#8220;Installed&#8221;. Find Xamarin.Forms, and check the UWP project to install the same version of Xamarin.Forms into your UWP app.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22916\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Add-Forms-to-UWP-1024x594.png\" alt=\"Add Forms to UWP\" width=\"600\" \/><\/p>\n<p>Now, add your shared code that contains your Models, Views, and ViewModels. Inside the UWP application right-click &#8220;References&#8221;, and select &#8220;Add Reference&#8221;. Under projects, you will will find all of the projects in your solution. Find your PCL project or shared project, check it, and click OK.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22920\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Reference-Manager1-1024x511.png\" alt=\"Reference Manager\" width=\"600\" \/><\/p>\n<h3>Update App.xaml.cs<\/h3>\n<p>All Windows apps have an App.xaml for application-level configuration. Just like a Xamarin.Forms XAML page, this page also has a C# code behind file for lifecycle events. Open it up and you will find an <em>OnLaunched<\/em> method.<\/p>\n<p>Find the following line of code:<\/p>\n<pre class=\"lang:csharp decode:true\">rootFrame.NavigationFailed += OnNavigationFailed;<\/pre>\n<p>and add the Xamarin.Forms <em>Init<\/em> call:<\/p>\n<pre class=\"lang:csharp decode:true\">Xamarin.Forms.Forms.Init (e);<\/pre>\n<h3>Update MainPage.xaml<\/h3>\n<p>Open up MainPage.xaml of the Windows 10 app and remove the default &#8220;Grid&#8221; that was created for you so that the page is now completely empty. Next, add a new namespace in the XAML and change the <em>Page<\/em> to be a Xamarin.Forms <em>Page<\/em>:<\/p>\n<pre class=\"lang:xml decode:true\">\n\n\n<\/pre>\n<h3>Update MainPage.xaml.cs<\/h3>\n<p>Update the code behind file to initialize your Xamarin.Forms app:<\/p>\n<pre class=\"lang:csharp decode:true\">public sealed partial class MainPage\n{\n  public MainPage()\n  {\n    InitializeComponent();\n    LoadApplication (new YOUR_NAMESPACE.App());\n  }\n}\n<\/pre>\n<p>Replace YOUR_NAMESPACE with the namespace that is found in your Xamarin.Forms <em>Application<\/em> class, which is usually located in your shared code under App.cs.<\/p>\n<h2>Configure App to Deploy<\/h2>\n<p>Sometimes Visual Studio may not set new project to build and compile by default. To ensure that it does, right-click the solution and open up the Configuration Manager. Check the UWP app to build and deploy, and you are all set!<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-22918\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Configuration-Manager1-1024x642.png\" alt=\"Configuration Manager\" width=\"600\" \/><\/p>\n<h2>Add images assets and any other NuGets<\/h2>\n<p>The last step is to simply add any image assets or add back in any NuGet or Plugins for Xamarin that you may have as a dependency. Be sure that any of these dependencies have also add Windows 10 (UWP) support for compatibility.<\/p>\n<h2>Learn more and provide feedback<\/h2>\n<p>To learn more about all of the new features in <a href=\"https:\/\/developer.xamarin.com\/releases\/xamarin-forms\/xamarin-forms-2.0\/2.0.0\/\">Xamarin.Forms 2.0<\/a> be sure to read through the release notes. You can check out the full source code for the weather sample application shown above on my <a href=\"https:\/\/github.com\/jamesmontemagno\/MyWeather.Forms\">GitHub<\/a>. Windows 10 (UWP) support is in preview, so there is a possibility that you may run into some rough edges. To help make Xamarin.Forms for UWP amazing, please be sure to leave feedback by\u00a0<a href=\"https:\/\/bugzilla.xamarin.com\/enter_bug.cgi?alias=&amp;assigned_to=&amp;attachurl=&amp;blocked=&amp;bug_file_loc=http%3A%2F%2F&amp;bug_severity=normal&amp;bug_status=NEW&amp;cf_tags=&amp;comment=&amp;contenttypeentry=&amp;contenttypemethod=autodetect&amp;contenttypeselection=text%2Fplain&amp;data=&amp;deadline=&amp;dependson=&amp;description=&amp;estimated_time=&amp;form_name=enter_bug&amp;maketemplate=Remember%20values%20as%20bookmarkable%20template&amp;op_sys=Mac%20OS&amp;product=Forms&amp;rep_platform=PC&amp;short_desc=&amp;target_milestone=UWP&amp;version=1.5.1\">filing an issue<\/a>\u00a0if you experience one.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the release of Xamarin 4 came Xamarin.Forms 2.0, introducing new features and optimizations to help you build great native cross-platform mobile apps. In addition to ListView caching strategies, pinch gestures, and new properties came the first public preview of Xamarin.Forms for Windows 10 (UWP) applications. While Xamarin.Forms already supports Windows Phone and Store targets, [&hellip;]<\/p>\n","protected":false},"author":544,"featured_media":22922,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4,16],"class_list":["post-22890","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform","tag-xamarin-forms"],"acf":[],"blog_post_summary":"<p>With the release of Xamarin 4 came Xamarin.Forms 2.0, introducing new features and optimizations to help you build great native cross-platform mobile apps. In addition to ListView caching strategies, pinch gestures, and new properties came the first public preview of Xamarin.Forms for Windows 10 (UWP) applications. While Xamarin.Forms already supports Windows Phone and Store targets, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/22890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/544"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=22890"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/22890\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=22890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=22890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=22890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}