Hello,
Yes, you can. Please use Linear gradient brushes, and refer to the following code:
internal class HorizontalLinearGradientPaintDrawable : IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
LinearGradientPaint linearGradientPaint = new LinearGradientPaint
{
StartColor = Colors.Yellow,
EndColor = Colors.Green,
// StartPoint is already (0,0)
EndPoint = new Point(1, 0)
};
RectF linearRectangle = new RectF(10, 10, 200, 100);
canvas.SetFillPaint(linearGradientPaint, linearRectangle);
// canvas.SetShadow(new SizeF(10, 10), 10, Colors.Grey);
canvas.FillRoundedRectangle(linearRectangle, 12);
}
You could also set verticalLinearGradientDrawable, diagonalLinearGradientDrawable, fourColorLinearGradientDrawable. For more details, please see the official sample- maui-samples/9.0/UserInterface/Views/GraphicsViewDemos/GraphicsViewDemos/Views/LinearGradientPaintPage.xaml at main · dotnet/maui-samples
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.