Working with the GraphicsView
This article shows how to use the GraphicsView control in MauiReactor
GraphicsView is a powerful control in .NET MAUI package that is capable of hiding all the complexity of using direct drawing commands among all the supported platforms: in other words, you can just place the control and issue drawing commands (like DrawReactangle, or DrawString).
Drawing graphics objects like Text, Rectangles, or Shapes in GraphicsView is generally more performant than creating native controls like Labels. In the brief article will see how to instantiate and use a GraphicsView in MauiReactor.
MauiReactor supports other means of drawing directly on a canvas. Please refer to this page to learn which are the other ways.
GraphicsView usage is pretty simple: you have just to create it and provide a function for its OnDraw callback where you can issue commands on the Canvas object in order to draw lines, text, shapes, and so on.
Let's start creating a page with a GraphicsView control inside a page and handle the OnDraw callback:
This should result in something similar to the below screen:
Please note that under iOS and macOS the GraphicsView has a default black background while under Android has transparent default. You should consider setting the background of the canvas to a specific value.
To make the test a bit more interesting let's convert the component into a stateful one and rotate the text with a slider as shown in the following code:
As you can see we can access State properties inside the OnDraw
method as well.
Hot-reloading can handle any modifications to the GraphicsView control including the OnDraw callback.
This should be the resulting behavior:
Last updated