The following shapes are made with XAML and the namespace of Microsoft.Maui.Controls.Shapes. It is more developed than BoxView type, supporting more enhancement such as curves and paths.
Path: Generates an appearance by means of vectors.
PathGeometry: Tells about the synthesis of shapes including original geometry.
PathFigure: Stands for part of the path from a particular point.
LineSegment and ArcSegment: Define line and arc segments.
GraphicsView
GraphicsView is one of the main components which is able the handle drawing on the Microsoft.Maui.Graphics drawing platform. It provides you more ability to graphics than the normal control so you can get better and complicated graphics.
namespace MauiAppExample
{
public partial class GraphicsViewPage : ContentPage
{
public GraphicsViewPage()
{
InitializeComponent();
MyGraphicsView.Drawable = new CustomDrawable();
}
}
public class CustomDrawable : IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
// Draw a blue rectangle
canvas.FillColor = Colors.Blue;
canvas.FillRectangle(50, 50, 200, 100);
// Draw a red circle
canvas.FillColor = Colors.Red;
canvas.FillCircle(150, 200, 50);
// Draw a green line
canvas.StrokeColor = Colors.Green;
canvas.StrokeSize = 4;
canvas.DrawLine(0, 0, dirtyRect.Width, dirtyRect.Height);
}
}
}
GraphicsView: A Drawable view used with a path that is set in the XAML and which contains a reference to a custom draw object (MyDrawable).
IDrawable Interface:
CustomDrawable is a class that implements basic IDrawable interface and thus offers additional drawing capabilities.
Draw Method: Informs what should be drawn in the canvas.
FillRectangle: Draws a blue rectangle.
FillCircle: Draws a red circle.
DrawLine: It paints a green diagonal line across the view.