Hi Michael,
This is totally doable. I have two options for you:
- Use the RadSweepGradientBrush (easy, can be done in XAML)
- Use the SkiaSharp drawing libraries (harder, is done in C#, but more powerful)
Telerik Option - Path & SweepGradientBrush
Let me show you how to use our option. this is lightweight and easy to use. Just create a RadPath element/shape and use a RadSweepGradientBrush to fill it.
As an example of it in action, visit the RadPath Styling documentation. For your convenience, here's the code example from that article:
<telerikPrimitives:RadPath x:Name="gradientPath"
StrokeThickness="1"
Stroke="White"
Geometry="{x:Static telerikInput:Geometries.Diamond}">
<telerikPrimitives:RadPath.Fill>
<telerikCommon:RadSweepGradientBrush>
<x:Arguments>
<Point>0.5, 0.5</Point>
</x:Arguments>
<telerikCommon:RadSweepGradientStop>
<x:Arguments>
<Color>#1481FF</Color>
<x:Double>180</x:Double>
</x:Arguments>
</telerikCommon:RadSweepGradientStop>
<telerikCommon:RadSweepGradientStop>
<x:Arguments>
<Color>#BCE1FF</Color>
<x:Double>360</x:Double>
</x:Arguments>
</telerikCommon:RadSweepGradientStop>
</telerikCommon:RadSweepGradientBrush>
</telerikPrimitives:RadPath.Fill>
</telerikPrimitives:RadPath>
Note:
This is not a Xamarin.Forms.Color object that you can set on any plain Xamarin.Forms View element's BackgroundColor property. If you want to make a gradient background, you'll need to place a RadPath there so you can use the gradient brush inside it.
For example, let's say you wanted a gradient sweep on a Grid background, you'd place the RadPath at the bottom of the Grid's children:
<Grid>
<RadPath Fill="Your_Gradient" />
<TheOtherStuffHere />
</Grid>
Microsoft Option - SkiaSharp
If this is not sufficient for your needs, you can use the Xamarin.Forms SkiaSharp library directly. This option is a bit more complicated because you're manually handing the surface and paint event, but it will achieve just about any custom drawing options you need.
Visit the following amazing Microsoft documentation article https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/effects/shaders/linear-gradient. (I think it was written by Charles Petzold).
Wrapping Up
I hope I was able to answer your question. If you have any trouble using the Path or SweepGradient, feel free to open a support ticket and get one-on-one help from the developers and support team.
Regards,
Lance | Team Lead - US DevTools Support
Progress Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items