{"id":16196,"date":"2015-01-13T16:10:09","date_gmt":"2015-01-13T21:10:09","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=16196"},"modified":"2015-01-13T16:10:09","modified_gmt":"2015-01-13T21:10:09","slug":"major-enhancements-to-xamarin-forms","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/major-enhancements-to-xamarin-forms\/","title":{"rendered":"Major Enhancements to Xamarin.Forms"},"content":{"rendered":"<p>\t\t\t\tXamarin.Forms is a powerful library that enables developers to build native user interfaces from a shared C# code base for iOS, Android, and Windows Phone. The latest release, Xamarin.Forms 1.3, introduces several major enhancements to the platform to increase productivity and to extend your application even further. Additionally, this release also brings Unified support for iOS applications built with Xamarin.Forms to coincide with the release of Xamarin.iOS 8.6, which is required for this update.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-16234\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/crm-app.png\" alt=\"crm-app\" width=\"915\" height=\"300\" \/><\/p>\n<h2>Application Lifecycle<\/h2>\n<p>It is now easier than ever to respond to application lifecycle events in your Xamarin.Forms applications. With the new <code>Application<\/code> base class you can tap into several lifecycle methods such as <code>OnStart<\/code>, <code>OnSleep<\/code>, and <code>OnResume<\/code>. The Application class also delivers a simplified solution for specifying your MainPage of your application. Here is an example of what your new Application class might look like:<\/p>\n<pre class=\"lang:csharp decode:true\">\npublic class App : Xamarin.Forms.Application\n{\n    public App ()\n    {\n        MainPage = new ContentPage { Title = &quot;App Lifecycle Sample&quot; }; \/\/ your page here\n    }\n\n    protected override void OnStart()\n    {\n        \/\/ Handle when your app starts\n        Debug.WriteLine (&quot;OnStart&quot;);\n    }\n\n    protected override void OnSleep()\n    {\n        \/\/ Handle when your app sleeps\n        Debug.WriteLine (&quot;OnSleep&quot;);\n    }\n\n    protected override void OnResume()\n    {\n        \/\/ Handle when your app resumes\n        Debug.WriteLine (&quot;OnResume&quot;);\n    }\n}\n<\/pre>\n<p>Be sure to read through our <a href=\"http:\/\/developer.xamarin.com\/guides\/cross-platform\/xamarin-forms\/working-with\/app-lifecycle\/\" title=\"Xamarin.Forms Application Lifecycle\">Xamarin.Forms Application Lifecycle documentation<\/a> on how to get started using or transitioning your app to take advantage of these new events.<\/p>\n<h2>Styles<\/h2>\n<p>Xamarin developers love that they are able to use XAML to declare their user interfaces across iOS, Android, and Windows Phone. However, the immense amount of properties on controls can make your XAML cluttered. Additionally, if you wanted to change the look across all of your controls, you had to update each and every control. The introduction of <code>Styles<\/code> alleviates this issue by allowing you to define control defaults, known as styles, in your <code>ResourceDictionary<\/code>. Here is an example of what a few buttons might look like on a page:<\/p>\n<pre class=\"lang:xml decode:true\">\n&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;\n&lt;ContentPage xmlns=&quot;http:\/\/xamarin.com\/schemas\/2014\/forms&quot; \n\t     xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml&quot; \n             x:Class=&quot;StylesApps.MyPage&quot;&gt;\n  &lt;ContentPage.Content&gt;\n    &lt;StackLayout Padding=&quot;10&quot; Spacing=&quot;10&quot;&gt;\n      &lt;Button Text=&quot;Login&quot;\n              HorizontalOptions = &quot;FillAndExpand&quot;\n              HeightRequest = &quot;42&quot;\n              BackgroundColor = &quot;#77d065&quot;\n              BorderColor = &quot;Black&quot;\n              BorderRadius = &quot;5&quot;\n              BorderWidth = &quot;0&quot;\n              TextColor = &quot;White&quot;\/&gt;\n      &lt;Button Text=&quot;Logout&quot;\n              HorizontalOptions = &quot;FillAndExpand&quot;\n              HeightRequest = &quot;42&quot;\n              BackgroundColor = &quot;#77d065&quot;\n              BorderColor = &quot;Black&quot;\n              BorderRadius = &quot;5&quot;\n              BorderWidth = &quot;0&quot;\n              TextColor = &quot;White&quot;\/&gt;\n      &lt;Button Text=&quot;Register&quot;\n              HorizontalOptions = &quot;FillAndExpand&quot;\n              HeightRequest = &quot;42&quot;\n              BackgroundColor = &quot;#77d065&quot;\n              BorderColor = &quot;Black&quot;\n              BorderRadius = &quot;5&quot;\n              BorderWidth = &quot;0&quot;\n              TextColor = &quot;White&quot;\/&gt;\n    &lt;\/StackLayout&gt;\n  &lt;\/ContentPage.Content&gt;\n&lt;\/ContentPage&gt;\n<\/pre>\n<p>You can see there are a lot of properties that are the same across all of these buttons. To clean this up, you simply need define a base style in the ContentPage&#8217;s Resources, and then set the Button&#8217;s <code>Style<\/code> property to the Key.<\/p>\n<pre class=\"lang:xml decode:true\">\n&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;ContentPage xmlns=&quot;http:\/\/xamarin.com\/schemas\/2014\/forms&quot; \n\t\t\txmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml&quot; \n\t\t\tx:Class=&quot;StylesApps.MyPage&quot;&gt;\n  &lt;ContentPage.Resources&gt;\n    &lt;ResourceDictionary&gt;\n      &lt;Style x:Key=&quot;ButtonStyle&quot; TargetType=&quot;Button&quot;&gt;\n         &lt;Setter Property=&quot;HorizontalOptions&quot; Value=&quot;FillAndExpand&quot;\/&gt;\n         &lt;Setter Property=&quot;BackgroundColor&quot; Value=&quot;#77d065&quot;\/&gt;\n         &lt;Setter Property=&quot;BorderColor&quot; Value=&quot;Black&quot;\/&gt;\n         &lt;Setter Property=&quot;HeightRequest&quot; Value=&quot;42&quot;\/&gt;\n         &lt;Setter Property=&quot;BorderRadius&quot; Value=&quot;5&quot;\/&gt;\n         &lt;Setter Property=&quot;BorderWidth&quot; Value=&quot;0&quot; \/&gt;\n         &lt;Setter Property=&quot;TextColor&quot; Value=&quot;White&quot;\/&gt;\n      &lt;\/Style&gt;\n    &lt;\/ResourceDictionary&gt;\n  &lt;\/ContentPage.Resources&gt;\n    &lt;ContentPage.Content&gt;\n      &lt;StackLayout Padding=&quot;10&quot; Spacing=&quot;10&quot;&gt;\n        &lt;Button Text=&quot;Login&quot; Style=&quot;{StaticResource ButtonStyle}&quot; \/&gt;\n        &lt;Button Text=&quot;Logout&quot; Style=&quot;{StaticResource ButtonStyle}&quot;\/&gt;\n        &lt;Button Text=&quot;Register&quot; Style=&quot;{StaticResource ButtonStyle}&quot;\/&gt;\n      &lt;\/StackLayout&gt;\n  &lt;\/ContentPage.Content&gt;\n&lt;\/ContentPage&gt;\n<\/pre>\n<p>Now, adjusting any of the properties in the style will automatically apply to all of the buttons on the page that have this style set.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-medium wp-image-16231\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/Styles2-300x250.png\" alt=\"Styles\" width=\"300\" height=\"250\" \/><\/p>\n<h2>Triggers<\/h2>\n<p>There are several types of triggers now available in Xamarin.Forms including event, data, and multi triggers. If you have never heard of a trigger in styling before, they are essentially objects that enable you to apply changes when certain conditions are met on a control. For instance, you may want to scale up an <code>Entry<\/code> field when it has focus and also turn the text green. The code to implement this is as simple as extending the <code>Style<\/code> for a control in the resources. When the trigger&#8217;s property is met, the setter will be executed automatically. When the trigger&#8217;s property is not met, or changes, the setters will be returned to their original values.<\/p>\n<pre class=\"lang:xml decode:true\">\n&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?--&gt;\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;ContentPage xmlns=&quot;http:\/\/xamarin.com\/schemas\/2014\/forms&quot;     \n             xmlns:x=&quot;http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml&quot; \n             x:Class=&quot;StylesApps.MyPage2&quot;&gt;\n  &lt;ContentPage.Resources&gt;\n    &lt;ResourceDictionary&gt;\n      &lt;Style x:Key=&quot;EntryTrigger&quot; TargetType=&quot;Entry&quot;&gt;\n        &lt;Style.Triggers&gt;\n          &lt;Trigger Property=&quot;IsFocused&quot; Value=&quot;True&quot; TargetType=&quot;Entry&quot;&gt;\n            &lt;Setter Property=&quot;Scale&quot; Value=&quot;1.1&quot; \/&gt;\n            &lt;Setter Property=&quot;TextColor&quot; Value=&quot;Green&quot; \/&gt;\n          &lt;\/Trigger&gt;\n        &lt;\/Style.Triggers&gt;\n      &lt;\/Style&gt;\n    &lt;\/ResourceDictionary&gt;\n  &lt;\/ContentPage.Resources&gt;\n  &lt;ContentPage.Content&gt;\n    &lt;StackLayout Padding=&quot;20&quot; Spacing=&quot;10&quot;&gt;\n      &lt;Entry Placeholder=&quot;Username&quot; Style=&quot;{StaticResource EntryTrigger}&quot; \/&gt;\n      &lt;Entry Placeholder=&quot;Password&quot; Style=&quot;{StaticResource EntryTrigger}&quot;\/&gt;\n      &lt;Button Text=&quot;Login&quot; \/&gt;\n    &lt;\/StackLayout&gt;\n  &lt;\/ContentPage.Content&gt;\n&lt;\/ContentPage&gt;\n\n<\/pre>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-16233\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/ezgif.com-crop-1.gif\" alt=\"Xamarin.Forms Triggers\" width=\"239\" height=\"360\" \/><\/p>\n<h2>Navigation Stack<\/h2>\n<p>The navigation system in Xamarin.Forms has also been overhauled in 1.3 to enable you to push, pop, and insert pages easily. In addition you can now specify whether you would like to animate pages in and out during navigation. Here is a look at the new INavigation API:<\/p>\n<pre class=\"lang:csharp decode:true\">\npublic interface INavigation\n{\n    IReadOnlyList NavigationStack { get; }\n    IReadOnlyList ModalStack { get; }\n\n    void RemovePage (Page page);\n    void InsertPageBefore (Page page, Page before);\n\n    Task PushAsync (Page page);\n    Task PopAsync ();\n    Task PopToRootAsync ();\n    Task PushModalAsync (Page page);\n    Task PopModalAsync ();\n\n    Task PushAsync (Page page, bool animated);\n    Task PopAsync (bool animated);\n    Task PopToRootAsync (bool animated);\n    Task PushModalAsync (Page page, bool animated);\n    Task PopModalAsync (bool animated);\n}\n<\/pre>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-16232\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/ezgif.com-crop.gif\" alt=\"Xamarin.Forms navigation\" width=\"239\" height=\"360\" \/><\/p>\n<p>In addition to these updates you will also find a new virtual method on any of your Pages: <code>OnBackButtonPressed()<\/code>, which allows you to tap in to find out when the physical back button was pressed on the device. Combining these updates together give you much more flexibility when building your application.<\/p>\n<h2>So Much More<\/h2>\n<p>These features are just the beginning of everything packed into Xamarin.Forms 1.3. You can read about the plethora of features and fixes in this release on the <a href=\"http:\/\/forums.xamarin.com\/discussion\/29934\" title=\"Xamarin.Forms 1.3 release notes\">Xamarin Forums<\/a>. Additionally, you will find new additions and updates to our <a href=\"http:\/\/developer.xamarin.com\/guides\/cross-platform\/xamarin-forms\/working-with\/\" title=\"Xamarin.Forms documentation\">comprehensive documentation<\/a> on our developer portal to help you get started with this release.<\/p>\n<p>*Note: Versions 1.3.0 and 1.3.1 have identical APIs except that the latter has support for the Unified API in Xamarin.iOS 8.6.<\/p>\n<h2>Learn More Live<\/h2>\n<p>To see Xamarin.Forms 1.3 in action covering these new features and much more, check out this <a href=\"https:\/\/xamarin.wistia.com\/medias\/iv56gm6y2r\" target=\"_blank\">webinar recording<\/a> with Xamarin&#8217;s Craign Dunn.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xamarin.Forms is a powerful library that enables developers to build native user interfaces from a shared C# code base for iOS, Android, and Windows Phone. The latest release, Xamarin.Forms 1.3, introduces several major enhancements to the platform to increase productivity and to extend your application even further. Additionally, this release also brings Unified support for [&hellip;]<\/p>\n","protected":false},"author":544,"featured_media":39167,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4,16],"class_list":["post-16196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform","tag-xamarin-forms"],"acf":[],"blog_post_summary":"<p>Xamarin.Forms is a powerful library that enables developers to build native user interfaces from a shared C# code base for iOS, Android, and Windows Phone. The latest release, Xamarin.Forms 1.3, introduces several major enhancements to the platform to increase productivity and to extend your application even further. Additionally, this release also brings Unified support for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/16196","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=16196"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/16196\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=16196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=16196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=16196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}