MAUIverse MAUIverse

SkiaSharp and MVVM

A common question with SkiaSharp is how to get drawing logic out of the PaintSurface event handler and into a view model. David Britch shares his preferred approach for a clean MVVM setup in .NET MAUI.

What you’ll learn

  • Subclassing SKCanvasView — adding a CanvasRenderer bindable property that points at a rendering service
  • Defining a service interface — an IBitmapRendererService exposing PaintSurface, InvalidateSurface, and an invalidation event
  • Implementing the service — drawing an SKBitmap and raising redraw requests from a bindable Bitmap property
  • Injecting into a view model — registering the service and consuming it via dependency injection
  • Forcing redraws — calling InvalidateSurface from the view model to keep code-behind empty

Read the full post for the full control, interface, and service code, and a link to a working sample repo.

View Source →

← Back to Community Feed

}