To draw some graphics we just need to create a RxSKCanvasView and handle the OnPaintSurfacecallback (sample drawing code is freely copied from Xamarin doc):
publicclassMainPageState:IState { publicdouble RotationAngle { get; set; } }publicclassMainPage:RxComponent<MainPageState> {publicoverrideVisualNodeRender() {returnnewRxContentPage() {newRxSKCanvasView() .OnPaintSurface(OnPaintCanvasSurface) }; }privatevoidOnPaintCanvasSurface(SKPaintSurfaceEventArgs args) {SKImageInfo info =args.Info;SKSurface surface =args.Surface;SKCanvas canvas =surface.Canvas;canvas.Clear();string text ="OUTLINE"; // Create an SKPaint object to display the textSKPaint textPaint =newSKPaint { Style =SKPaintStyle.Stroke, StrokeWidth =1, FakeBoldText =true, Color =SKColors.Blue }; // Adjust TextSize property so text is 95% of screen widthfloat textWidth =textPaint.MeasureText(text);textPaint.TextSize=0.95f*info.Width*textPaint.TextSize/ textWidth; // Find the text boundsSKRect textBounds =newSKRect();textPaint.MeasureText(text, ref textBounds); // Calculate offsets to center the text on the screenfloat xText =info.Width/2-textBounds.MidX;float yText =info.Height/2-textBounds.MidY; // And draw the textcanvas.DrawText(text, xText, yText, textPaint); } }
If you run the app you should something like this:
Now let's add some interactivity: for example adding the ability to rotate the text. We need a state that hold the current rotation angle, a slider to allow user modify this value, finally we need to invalidate SkiaSharp canvas when angle changes: