20

Are there any libraries which

  1. Allow to draw svg direct to a Windows Forms application
  2. to a WPF application

I draw graphics and design everything with Inkscape, because I love that program. Then I have those stunning svgs and have to either export them to png (WinForm) to use them or convert them to xaml-code (WPF) (Kaxaml helps me).

Is there a way to directly use my svgs?

Xn0vv3r
  • 17,766
  • 13
  • 58
  • 65

4 Answers4

10

Wow, I just read that Inkscape supports saving as XAML. I didn't realize that up to now shame.

But that still doesn't solve my problems with WinForms...

Xn0vv3r
  • 17,766
  • 13
  • 58
  • 65
7

I personally hate how there's no native support for SVG in Microsoft's products/development tools. I've found two fairly complete but still immature SVG libraries that seem to be active as of this writing, definitely in need of contributors though.

IIRC both libraries output a Drawing object which can be used directly through the Image class; You'll figure it out, they're both pretty straightforward to use.

hannson
  • 4,465
  • 8
  • 38
  • 46
  • 1
    I want to add this tool to the list: https://github.com/BerndK/SvgToXaml I wrote it, because I wasn't satisfied with the other tools, sure it is also open source. – BerndK May 07 '15 at 19:32
6

If you want to load them directly into WPF, I got better results from: https://github.com/ElinamLLC/SharpVectors

Soleil
  • 6,404
  • 5
  • 41
  • 61
Danny Varod
  • 17,324
  • 5
  • 69
  • 111
4

Yes, you can use ReaderSVG from AB4D to get WPF directly from XAML.

Regarding WinForms, removed a previous link to Kent Boogart's example as it was deleted sometime in 2019.

Copy below from this dotnetways post

To host a WPF control or WPF user control (wpfControl in this example) into Windows Form application, create an instance of ElementHost Class and add your WPF control/user control as child to the instance of ElementHost.

    using System.Windows.Forms.Integration;   
    //Assembly:   WindowsFormsIntegration (in WindowsFormsIntegration.dll) 

//...

    ElementHost elementHost = new ElementHost();  
    elementHost.Dock = DockStyle.None;  
    elementHost.Child = wpfControl; 

Now, add the instance of ElementHost to a container control in your windows form (for instance containerPanel here)

    containerPanel.Controls.Add(elementHost);  
Andy Dent
  • 17,578
  • 6
  • 88
  • 115