I am trying to render some lines on a .NET MAUI GraphicsView. The lines are stored as Vector2 data in an array on my MainPage.
My problem is that I don't know how to pass variable data from the MainPage into the Draw() method of the IDrawable class. In the GraphicsViewDemos are a lot of examples but they load files from the app's ressources and they don't show how to pass data into it. My goal is to update the canvas in realtime.
Here is an example of a single hardcoded line from the demos:
internal class GraphicsDrawable: IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.StrokeColor = Colors.Red;
canvas.StrokeSize = 6;
canvas.DrawLine(10, 10, 90, 100);
}
}
In the Mainpage.xaml is following code:
<ContentPage.Resources>
<drawable:GraphicsDrawable x:Key="drawable" />
</ContentPage.Resources>
and
<GraphicsView Drawable="{StaticResource drawable}"
HeightRequest="300"
WidthRequest="400" />