Back to results for “GraphicsView”
.NET MAUI › Graphics & Drawing

How do you handle touch/gesture input on a GraphicsView for interactive drawing?

Advanced

Answer

Attach gesture recognizers (PanGestureRecognizer, TapGestureRecognizer) or handle pointer events, translate the touch points into your drawable's coordinate space, update model state, and call Invalidate. For freehand drawing, accumulate points on pan and render them as a path.
var pan = new PanGestureRecognizer();
pan.PanUpdated += (s, e) =>
{
    _points.Add(new PointF((float)e.TotalX, (float)e.TotalY));
    graphicsView.Invalidate();
};
graphicsView.GestureRecognizers.Add(pan);
Real-world example A signature-capture control records pan points and repaints the stroke live as the user signs.

Common follow-ups: How do you map touch to canvas coordinates? | Which recognizer suits freehand?