SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

How to implement SKCanvasView in Blazor it works in MAUI

Open peder1896 opened this issue 4 years ago • 1 comments

Hi I have a MAUI app with a SKCanvasView decalared as this <skia:SKCanvasView WidthRequest="1300" HeightRequest="1300" x:Name="GpuView" PaintSurface="OnPaintCanvas" gnorePixelScaling="True" VerticalOptions="Start" orizontalOptions="Start" /> i call OnPaintCanvas in codebehind and it works with Application.Current.Dispatcher.Dispatch(() => { if (GpuView != null) GpuView.InvalidateSurface(); });

Now i tried this in Blazor <SkiaSharp.Views.Blazor.SKCanvasView Width="1024px" Height="1024px" id=@CanvasID OnPaintSurface="OnPaintCanvas" EnableRenderLoop="false" />

How do I call OnPaintCanvas from codebehind in Blazor, it is called if i declare EnableRenderLoop="true" but I want to call it myself to save CPU and later on GPU when SKGLView works in Blazor Thanks

peder1896 avatar Jun 19 '22 19:06 peder1896

Solved by using <SkiaSharp.Views.Blazor.SKCanvasView Width="1024px" Height="1024px" @ref="CanvasView" id=@CanvasID OnPaintSurface="OnPaintCanvas" EnableRenderLoop="false" />

it was the @ref="CanvasView" that made it work, to redraw call from code with CanvasView.Invalidate();

peder1896 avatar Aug 10 '22 19:08 peder1896