Xn0vv3r
Xn0vv3r

Reputation: 18184

Library for using SVG in Windows Forms / WPF?

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?

Upvotes: 20

Views: 17364

Answers (4)

Danny Varod
Danny Varod

Reputation: 18118

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

Upvotes: 6

Andy Dent
Andy Dent

Reputation: 17981

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);  

Upvotes: 4

hannson
hannson

Reputation: 4525

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.

Upvotes: 7

Xn0vv3r
Xn0vv3r

Reputation: 18184

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...

Upvotes: 10

Related Questions