Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boxview "LinearGradientBrush"

How can I do same gradient effect like in the code below in xamarin forms?

The same effect in WPF:

<Rectangle Width="200" Height="100">
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
      <GradientStop Color="Yellow" Offset="0.0" />
      <GradientStop Color="Red" Offset="0.25" />
      <GradientStop Color="Blue" Offset="0.75" />
      <GradientStop Color="LimeGreen" Offset="1.0" />
    </LinearGradientBrush>
  </Rectangle.Fill>
</Rectangle>

My Boxview in xamarin forms:

<BoxView WidthRequest="100" Grid.RowSpan="2">

</BoxView>
like image 743
FoksaK Avatar asked Oct 29 '25 05:10

FoksaK


1 Answers

There is more than one way to do it. You can use SkiaSharp to achieve the result. Otherwise, you can write custom renderers to do the same.

Refer to the Xamarin documentation here if you wish to use the SkiaSharp library.

Refer below links if you wish to use custom renderers to achieve the result.

  • Add Gradient background to layouts in Xamarin Forms visual studio
  • Horizontal And Vertical Gradient Color In Xamarin.Forms

There is an awesome custom control MagicGradients available for doing some excellent gradient works which would be very handy if you prefer to write very less code.

Refer to the below links:

  • GitHub source code - MagicGradients
  • NuGet Package - MagicGradients

There is also an excellent blog available for the same on how to use the control if you are a beginner.

I hope that helps.

like image 104
Harikrishnan Avatar answered Oct 30 '25 23:10

Harikrishnan