Search code examples
canvasuwpuser-controlsuno-platform

UWP UserControl with Canvas: how do you draw?


For the Uno platform, based on UWP, I want to create a UserControl which contains a Canvas where I can draw something. I can't find any documentation or examples on what drawing events occur and how to use them.

I believe my XAML can be, minimally, like this:

<UserControl
  x:Class="UnoTest.Shared.Controls.ExpandableImage"
  ...
  <Canvas />
</UserControl>

And the code behind like this:

namespace UnoTest.Shared.Controls
{
  public sealed partial class ExpandableImage : UserControl
  {
    public ExpandableImage()
    {
      this.InitializeComponent();
    }
  }
}

And, surely, there must be some callbacks for drawing on the canvas.


Solution

  • I would suggest using Win2D CanvasControl if you want to draw arbitrary graphics in a UserControl.

    SkiaSharp Uno Platform is also an option if you want to target the Uno Platform.