Search code examples
c#wpfwinformsinkcanvas

How can I add an InkCanvas element to a Winform?


From what I understand so far, the InkCanvas element is in the WPF Framework. To use that, I need an ElementHost control to host the InkCanvas element. I've been to the MSDN links, but the example it gives talks of creating a WPF User Control Library project and so on. It's not that bad, but it seems a bit much to just add a control to a Winform. Is there a simpler way to do this, or am I trying to oversimplify this?

Thanks.


Solution

  • This should work:

    ElementHost host = new ElementHost();
    InkCanvas ic = new InkCanvas();
    host.Child = ic;
    Controls.Add(host);
    

    As mentioned in comments, one needs to add the WPF assemblies as reference (WindowsBase, PresentationCore, PresentationFramework).