How to Make Stylish Gradient Backgrounds in Xamarin | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (919)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (150)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Stylish Gradient Backgrounds

How to Make Stylish Gradient Backgrounds in Xamarin.Forms

Nowadays, applying gradients is more popular and trendier in mobile design. A gradient is a gradual blending of one color to another. It creates color combinations that feel different and modern, and they provide a completely unique feel to UI designs. In Xamarin.Forms applications, you may be asked to set a gradient background for a layout or view, but it might require additional effort to accommodate this request. Syncfusion’s aim is to make things easier and save developers time. Based on this, we have added the Gradient View to our Xamarin control collection to make stylish gradients in your applications. To add a gradient design, just include the Gradient View as a background view of your application.

The Gradient View control supports two types of gradients: linear and radial. Now, I will explain how to apply a gradient background to a Xamarin.Forms application.

Refer to this documentation to add the Gradient View reference in your application. The Gradient View contains the BackgroundBrush property, where you can specify either linear or radial gradients based on your requirements.

<gradient:SfGradientView>
        <gradient:SfGradientView.BackgroundBrush>
        </gradient:SfGradientView.BackgroundBrush>
</gradient:SfGradientView>

Apply linear gradient

A linear gradient paints a view with multiple colors that blend with each other. In general, there are three kinds of linear gradient based on its direction: horizontal, vertical, and diagonal. The default linear gradient direction is diagonal.

The StartPoint and EndPoint properties of SfLinearGradientBrush represent the start and end points of the gradient value. The default value of StartPoint is (0,0), which is the upper-left corner, and the default EndPoint is (1,1), which is the lower-right corner. To change the gradient effect direction from left to right, change StartPoint to (0,0.5) and EndPoint to (1,0.5). Similarly, to change the direction to vertical, set StartPoint to (0.5,0) and EndPoint to (0.5,1). The following MSDN image shows the linear gradient axis direction.

MSDN Gradient axis

Linear Gradient in Diagonal Direction

SfGradientStop is a color block of the gradient brush and it specifies a color at an offset along the gradient axis. The Color property specifies the color of the gradient stop and the Offset property specifies the position of gradient stop’s color on the gradient axis. Gradients aren’t limited to two color shades. If you are in a colorful mood, you can add any number of color shades by adding SfGradientStop to the GradientStops collection.

<gradient:SfGradientView>
      <gradient:SfGradientView.BackgroundBrush>
            <gradient:SfLinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                  <gradient:SfLinearGradientBrush.GradientStops>
                        <gradient:SfGradientStop Color="#ff05cd" Offset="0.0" />
                        <gradient:SfGradientStop Color="#313196" Offset="1.0" />
                  </gradient:SfLinearGradientBrush.GradientStops>
            </gradient:SfLinearGradientBrush>
      </gradient:SfGradientView.BackgroundBrush>
</gradient:SfGradientView>

Now, you can apply this gradient view as a background view to your application to create the gradient style.

<Grid>
     <gradient:SfGradientView/>
     <!--Your application view-->
</Grid>

diagonal gradient view

Diagonal Linear Gradient

 

Apply radial gradient

A radial gradient paints a view with multiple colors that blend together and create a circular color effect. A radial gradient axis is defined by a circle and its color radius starts from its origin. You can set the color radius and origin by using the Radius and Center properties of SfRadialGradientBrush. Refer to this documentation to learn more about radius and center customization.

<gradient:SfGradientView>
      <gradient:SfGradientView.BackgroundBrush>
            <gradient:SfRadialGradientBrush x:Name="linear" Radius="1" Center="0.5,0.5">
                  <gradient:SfRadialGradientBrush.GradientStops>
                        <gradient:SfGradientStop Color="#ff05cd" Offset="0.0" />
                        <gradient:SfGradientStop Color="#313196" Offset="1.0" />
                  </gradient:SfRadialGradientBrush.GradientStops>
             </gradient:SfRadialGradientBrush>
      </gradient:SfGradientView.BackgroundBrush>
</gradient:SfGradientView>

radial gradient view

Circular Gradient

Gradient support for Button and Switch controls

In our 2019 Volume 2 release, we have provided gradient support for the Syncfusion Button and Switch controls to make it easy to apply gradient effects to them.

Button

You can set the gradient background for the Button control using the BackgroundGradient property as shown in the following code.

       
        <!--Linear gradient background-->
        <buttons:SfButton HeightRequest="40" WidthRequest="150" CornerRadius="20" Text="Linear">
            <buttons:SfButton.BackgroundGradient>
                <gradient:SfLinearGradientBrush>
                    <gradient:SfLinearGradientBrush.GradientStops>
                        <gradient:SfGradientStop Color="#51F1F2" Offset="0"/>
                        <gradient:SfGradientStop Color="#2F9BDF" Offset="1"/>
                    </gradient:SfLinearGradientBrush.GradientStops>
                </gradient:SfLinearGradientBrush>
            </buttons:SfButton.BackgroundGradient>
        </buttons:SfButton>
        
        <!--Radial gradient background-->
        <buttons:SfButton HeightRequest="40" WidthRequest="150" CornerRadius="20" Text="Radial">
            <buttons:SfButton.BackgroundGradient>
                <gradient:SfRadialGradientBrush Radius="1">
                    <gradient:SfRadialGradientBrush.GradientStops>
                        <gradient:SfGradientStop Color="#FFB57B" Offset="0"/>
                        <gradient:SfGradientStop Color="#FF5361" Offset="1"/>
                    </gradient:SfRadialGradientBrush.GradientStops>
                </gradient:SfRadialGradientBrush>
            </buttons:SfButton.BackgroundGradient>
        </buttons:SfButton>

Gradient Syncfusion button

Linear (Left) and Radial (Right) Gradients in the Button Control

Switch

You can apply the gradient effect in both the track and thumb of the Switch control by using the TrackGradient and ThumbGradient properties.

     
<buttons:SfSwitch VisualType="Custom">
    <buttons:SfSwitch.SwitchSettings>
          <syncfusion:MaterialSwitchSettings>
                <syncfusion:MaterialSwitchSettings.ThumbGradient>
                    <gradient:SfLinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1">
                          <gradient:SfLinearGradientBrush.GradientStops>
                                <gradient:SfGradientStop Color="#FFFF0199" Offset="0.0" />
                                <gradient:SfGradientStop Color="#FFFFFFFF" Offset="1.0" />
                          </gradient:SfLinearGradientBrush.GradientStops>
                    </gradient:SfLinearGradientBrush>
                </syncfusion:MaterialSwitchSettings.ThumbGradient>
                <syncfusion:MaterialSwitchSettings.TrackGradient>
                    <gradient:SfLinearGradientBrush>
                          <gradient:SfLinearGradientBrush.GradientStops>
                                <gradient:SfGradientStop Color="#55FF0199" Offset="0.0" />
                                <gradient:SfGradientStop Color="#FFFFFFFF" Offset="1.0" />
                          </gradient:SfLinearGradientBrush.GradientStops>
                    </gradient:SfLinearGradientBrush>
                </syncfusion:MaterialSwitchSettings.TrackGradient>
          </syncfusion:MaterialSwitchSettings>
    </buttons:SfSwitch.SwitchSettings>
</buttons:SfSwitch>

Gradient Syncfusion switch control

Switch Control with Linear Gradient

Summary

In app UI design, color is one of the most powerful design factors and it’s an important part of the latest design trends. As a result, gradients are very hot in the current design moment and can give your app a unique style. In this blog post, we walked through the simple way to apply gradients using the Syncfusion Gradient View control and its extended support in the Button and Switch views. In our upcoming releases, we will include this support for other possible Syncfusion controls to provide built-in gradient background support. I hope you will create or modify your app’s UI design with our Gradient View.

I have added the complete sample code in this GitHub repo. You can always download our free evaluation to see all our components in action. Also, explore our samples available in this GitHub repository. You can even evaluate samples we have available on Google Play and Microsoft Store.

If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forumDirect-Trac, or our feedback portal. As always, we are happy to assist you!

Tags:

Share this post:

Comments (5)

[…] How to Make Stylish Gradient Backgrounds in Xamarin.Forms (Sheik Syed) […]

thanks
but this SfGradien is trail
how to get the license for it

You can contact the Deputy Director (Ryan Madison) He will provide you a license quote $995

ryanm@syncfusion.com

Hey, when using this piece of code in my studio I am experiencing an error:”Error XFC0009: No property, BindableProperty, or event found for “BackgroundGradient”, or mismatching type between value and property.”:

Hi Mohammed,

Can you please share more details, such as a code example, replication steps to reproduce the issue? Also, you can create a support incident with details using the below link.
https://www.syncfusion.com/support/directtrac/incidents/newincident

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed