{"id":47726,"date":"2020-08-07T09:22:19","date_gmt":"2020-08-07T16:22:19","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/xamarin\/?p=47726"},"modified":"2020-08-07T09:22:24","modified_gmt":"2020-08-07T16:22:24","slug":"xamarinforms-4-8-gradients-brushes","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/xamarinforms-4-8-gradients-brushes\/","title":{"rendered":"Xamarin.Forms 4.8 &#8211; Gradients &#038; Brushes, Drag &#038; Drop, and More!"},"content":{"rendered":"<p>Today marks the release of Xamarin.Forms 4.8. With a collection of features and quality improvements, Xamarin.Forms will give you even more opportunities to build colorful, interactive cross-platform applications. Let us take a dive into all of the new features coming to you in Xamarin.Forms!<\/p>\n<h2>Gradients and Brushes<\/h2>\n<p>Xamarin.Forms is releasing experimental support for Gradients and Brushes. Brush allows you to &#8220;paint&#8221; an area of your application with the brushes output, and different brushes have different types of output. There are three types of brushes: Solid Colors, Linear Gradients, and Radial Gradients.<\/p>\n<p>Solid color brush allows you to paint an area with a solid color. Below, see an example of the XAML code used to create a solid gradient:<\/p>\n<pre class=\"prettyprint\">&lt;Frame Background=\"DarkBlue\"\n       BorderColor=\"LightGray\"\n       HasShadow=\"True\"\n       CornerRadius=\"12\"\n       HeightRequest=\"120\"\n       WidthRequest=\"120\"\/&gt;<\/pre>\n<p>The above XAML creates the corresponding solid gradient, seen below:<\/p>\n<p><center>\n  <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/SolidColorBrush.png\" alt=\"Solid color of dark blue in a frame\" width=\"414\" height=\"180\" class=\"aligncenter size-full wp-image-47732\" srcset=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/SolidColorBrush.png 414w, https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/SolidColorBrush-300x130.png 300w\" sizes=\"(max-width: 414px) 100vw, 414px\" \/>\n<\/center><\/p>\n<p>Linear gradient brush allows you to blend two (or more) colors together into a beautiful gradient. Decide where the gradient starts using the <code>StartPoint<\/code> property and the <code>EndPoint<\/code> property. Furthermore, these properties can be the targets of data bindings! Below, find an example of the XAML code used to create a linear gradient:<\/p>\n<pre class=\"prettyprint\">&lt;Frame BorderColor=\"LightGray\"\n       HasShadow=\"True\"\n       CornerRadius=\"12\"\n       HeightRequest=\"120\"\n       WidthRequest=\"120\"&gt;\n    &lt;Frame.Background&gt;\n        &lt;LinearGradientBrush StartPoint=\"0,0\"\n                             EndPoint=\"1,0\"&gt;\n            &lt;GradientStop Color=\"Yellow\"\n                          Offset=\"0.1\"\/&gt;\n            &lt;GradientStop Color=\"Green\"\n                          Offset=\"1.0\"\/&gt;\n        &lt;\/LinearGradientBrush&gt;\n    &lt;\/Frame.Background&gt;\n&lt;\/Frame&gt;<\/pre>\n<p>This XAML creates the corresponding linear gradient, seen below: <center>\n  <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/GradientBrush.png\" alt=\"A frame with a gradient going from yellow to green\" width=\"414\" height=\"182\" class=\"aligncenter size-full wp-image-47733\" srcset=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/GradientBrush.png 414w, https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/GradientBrush-300x132.png 300w\" sizes=\"(max-width: 414px) 100vw, 414px\" \/>\n<\/center><\/p>\n<p>Radial gradient paints the designated area with a radial gradient. Which allows the blending of two or more colors across a circle. You can also decide the center of the gradient using the <code>Center<\/code> property. As well as the radius of the gradient using the <code>Radius<\/code> property. Just like the linear gradient brush, the properties of the radial gradient brush are also bindable! Here is an example of the XAML code used to create a radial gradient:<\/p>\n<pre class=\"prettyprint\">&lt;Frame BorderColor=\"LightGray\"\n       HasShadow=\"True\"\n       CornerRadius=\"12\"\n       HeightRequest=\"120\"\n       WidthRequest=\"120\"&gt;\n    &lt;Frame.Background&gt;\n        &lt;RadialGradientBrush Center=\"0.5,0.5\"\n                             Radius=\"0.5\"&gt;\n            &lt;GradientStop Color=\"Red\"\n                          Offset=\"0.1\"\/&gt;\n            &lt;GradientStop Color=\"DarkBlue\"\n                          Offset=\"1.0\"\/&gt;\n        &lt;\/RadialGradientBrush&gt;\n    &lt;\/Frame.Background&gt;\n&lt;\/Frame&gt;<\/pre>\n<p>The above XAML creates the corresponding radial gradient, seen below: <center>\n  <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/RadialGradient.png\" alt=\"Xamarin.Forms 4.8, Gradients &#038; Brushes\" width=\"414\" height=\"179\" class=\"aligncenter size-full wp-image-47734\" srcset=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/RadialGradient.png 414w, https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/RadialGradient-300x130.png 300w\" sizes=\"(max-width: 414px) 100vw, 414px\" \/>\n<\/center><\/p>\n<p>Brushes and gradients allow your full creative abilities to be released through Xamarin.Forms! For more information, take a look at the brushes and gradients docs <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/user-interface\/brushes\/\">here<\/a>.<\/p>\n<h2>Drag &amp; Drop<\/h2>\n<p>Now, drag and drop items in your applications with Xamarin.Forms 4.8! By using drag and drop, move an item from one location to another in the application, or even to a different application! <center>\n  <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/DragAndDrop.gif\" alt=\"Animation showing off drag and drop of image between applications with Xamarin.Forms\" width=\"760\" height=\"480\" class=\"aligncenter size-full wp-image-47755\" \/>\n<\/center><\/p>\n<p>There are a few steps to go through when enabling drag and drop in an application:<\/p>\n<p>1&#46; Add a DragGestureRecognizer object to its GestureRecognizers collection.<\/p>\n<p>2&#46; Build a data package. For image and text controls, Xamarin.Forms automatically will make the data package for you! For other content you will need to construct your own data package.<\/p>\n<p>3&#46; Enable drop on an item by adding a <code>DropGestureRecognizer<\/code> object to its GestureRecognizers collection. Then setting the <code>DropGestureRecognizer.AllowDrop<\/code> property to True.<\/p>\n<p>4&#46; If needed, set the <code>DropGestureRecognizer.DragOver<\/code> event to indicate the type of operation that should be performed.<\/p>\n<p>5&#46; If needed, process the data package to receive the dropped content. Xamarin.Forms automatically processes the data package for images and text. However, for other content you will need to process the data package yourself.<\/p>\n<p>Drag &amp; drop is a great new gesture implemented in Xamarin.Forms to give you even more ways to interact with your application! Please note that this is shipping experimentally and you must enable the <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/internals\/experimental-flags\"><strong>DragAndDrop_Experimental<\/strong><\/a> flag. For more information about Drag &amp; drop, see the docs <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/app-fundamentals\/gestures\/drag-and-drop\">here<\/a>!<\/p>\n<h2>Flyout Backdrop Color<\/h2>\n<p>The introduction of the flyout backdrop color makes the shell is even more customizable! Changing the the flyout backdrop color changes the color of the overlay that covers the page of your application when opening the flyout backdrop. <center>\n  <div style=\"width: 380px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-47726-1\" width=\"380\" height=\"700\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/2020-07-26_21-17-44.mp4?_=1\" \/><a href=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/2020-07-26_21-17-44.mp4\">https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/2020-07-26_21-17-44.mp4<\/a><\/video><\/div>\n<\/center><\/p>\n<p>This new feature works by using another new feature. In order to set the flyout backdrop color, set the <code>Shell.FlyoutBackdrop<\/code> property to a Brush.<\/p>\n<p>One amazing part of this feature is that it actually works with another new features: brushes &amp; gradients! Once enabling the brushes feature, define a solid, gradient, or radial brush. Then assign it to the <code>Shell.FlyoutBackdrop<\/code> property. An example of the XAML that defines and assigns the brush to the flyout is displayed below:<\/p>\n<pre class=\"prettyprint\">&lt;Shell ...&gt;\n    &lt;FlyoutItem ...&gt;\n      &lt;Shell.FlyoutBackdrop&gt;\n          &lt;LinearGradientBrush StartPoint=\"0,0\"\n                               EndPoint=\"1,1\"&gt;\n              &lt;GradientStop Color=\"#8A2387\"\n                            Offset=\"0.1\" \/&gt;\n              &lt;GradientStop Color=\"#E94057\"\n                            Offset=\"0.6\" \/&gt;\n              &lt;GradientStop Color=\"#F27121\"\n                            Offset=\"1.0\" \/&gt;\n          &lt;\/LinearGradientBrush&gt;\n      &lt;\/Shell.FlyoutBackdrop&gt;\n      ...\n    &lt;\/FlyoutItem&gt;\n    ...\n&lt;\/Shell&gt;<\/pre>\n<p>By combining brushes and the flyout backdrop, you now have more control over the design of your flyouts! To learn more, look at the flyout <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/app-fundamentals\/shell\/flyout\">docs<\/a>.<\/p>\n<h2>Featured Contributor<\/h2>\n<p>Xamarin.Forms has <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/release-notes\/4.8\/4.8.0#thank-you\">dozens of contributors<\/a> constantly working to ensure a great experience. The Xamarin team wants to highlight individuals in our community who have constantly contributed to the success of Xamarin.Forms. Today we are highlighting Pedro!<\/p>\n<table width=\"100%\">\n<tr>\n<td valign=\"top\" width=\"200\">\n      <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/PedroJesus.jpeg\" alt=\"Image of Pedro Jesus\" width=\"460\" height=\"460\" class=\"aligncenter size-full wp-image-47741\" srcset=\"https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/PedroJesus.jpeg 460w, https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/PedroJesus-300x300.jpeg 300w, https:\/\/devblogs.microsoft.com\/xamarin\/wp-content\/uploads\/sites\/44\/2020\/08\/PedroJesus-150x150.jpeg 150w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/>\n    <\/td>\n<td>\n      <b>What is your name?<\/b><br \/> Pedro Henrique de Souza Jesus <\/p>\n<p> <b>Where are you based?<\/b><br \/>Brazil, state of Minas Gerais<\/p>\n<p> <b>How long have you been using Xamarin.Forms?<\/b><br \/>Three Years<\/p>\n<p> <b>What was the first application you developed?<\/b><br \/> An auxiliary tool to buy beer <\/p>\n<p> <b>What is your favorite NuGet package?<\/b><br \/> Xamarin.Essentials <\/p>\n<p> <b>Where can people find you online?<\/b><br \/> <a href=\"https:\/\/twitter.com\/pj_souz\">Twitter<\/a> &#038; <a href=\"https:\/\/github.com\/pictos\">Github<\/a>\n    <\/td>\n<\/tr>\n<\/table>\n<h2>Get Started Today<\/h2>\n<p>Update your projects from your favorite <a href=\"https:\/\/docs.microsoft.com\/xamarin\/cross-platform\/troubleshooting\/questions\/nuget-update\">NuGet package manager<\/a> today! Take advantage of <a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/release-notes\/4.8\/4.8.0\">the latest release<\/a>. Share your projects and progress with us online.<\/p>\n<p>We love your feedback on Xamarin Forms. Please <a href=\"https:\/\/github.com\/xamarin\/Xamarin.Forms\/issues\/new\/choose\">open issues on GitHub<\/a> for any additional enhancements or issues to discuss. For more information on this release check the resources below.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/release-notes\/4.8\/4.8.0\">Xamarin.Forms 4.8 Release Notes<\/a> <\/li>\n<li>Docs \n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/user-interface\/brushes\/\">Gradients &amp; Brushes<\/a> <\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/app-fundamentals\/gestures\/drag-and-drop\">Drag &amp; Drop<\/a> <\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/xamarin\/xamarin-forms\/app-fundamentals\/shell\/flyout\">Flyout Backdrop Color<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Check out the latest release of Xamarin.Forms 4.8 that introduces gradients, brushes, drag &#038; drop, and so much more! Head inside for all of the release details.<\/p>\n","protected":false},"author":31561,"featured_media":47733,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[5216,2,367],"tags":[8152,9022,409,9021,16],"class_list":["post-47726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcements","category-developers","category-xamarin-forms","tag-gradients","tag-paths","tag-releases","tag-shapes","tag-xamarin-forms"],"acf":[],"blog_post_summary":"<p>Check out the latest release of Xamarin.Forms 4.8 that introduces gradients, brushes, drag &#038; drop, and so much more! Head inside for all of the release details.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/47726","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\/31561"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=47726"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/47726\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/47733"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=47726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=47726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=47726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}