在 Windows 窗体/WPF 中使用 SVG 的库?

发布于 2024-07-11 14:28:05 字数 361 浏览 8 评论 0原文

是否有任何库

  1. 允许将 svg 直接绘制到 Windows 窗体应用程序
  2. 到 WPF 应用程序

我使用 Inkscape,因为我喜欢那个程序。 然后我有了那些令人惊叹的 svgs,必须将它们导出为 png (WinForm) 才能使用它们,或者将它们转换为 xaml 代码 (WPF) (Kaxaml 帮助我)。

有没有办法直接使用我的 svgs?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

晚雾 2024-07-18 14:28:05

,我只需阅读,Inkscape 支持另存为 XAML。 到目前为止我还没有意识到这一点羞耻

但这仍然不能解决我的 WinForms 问题......

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

森林散布 2024-07-18 14:28:05

我个人很讨厌 Microsoft 的产品/开发工具中没有对 SVG 的原生支持。 我发现了两个相当完整但仍不成熟的 SVG 库,在撰写本文时它们似乎很活跃,但肯定需要贡献者。

  • WPFSvg2Xaml(开源)
  • WinForms:< a href="http://svg.codeplex.com" rel="noreferrer">SVG 渲染引擎(开源)

IIRC 两个库都输出一个 Drawing 对象,可以通过 Image 类直接使用; 您会发现,它们都非常易于使用。

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.

酒废 2024-07-18 14:28:05

如果你想将它们直接加载到WPF中,
我从以下位置获得了更好的结果: https://github.com/ElinamLLC/SharpVectors

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

箹锭⒈辈孓 2024-07-18 14:28:05

是的,您可以使用 AB4D 中的 ReaderSVG 直接从 XAML 获取 WPF。

关于 WinForms,删除了 Kent Boogart 示例的先前链接,因为它在 2019 年的某个时候被删除。

复制以下内容 此 dotnetways 帖子

要将 WPF 控件或 WPF 用户控件(本例中为 wpfControl)托管到 Windows 窗体应用程序中,请创建 ElementHost 类的实例并添加 WPF 控件/用户控件作为 ElementHost 实例的子级。

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

//...

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

现在,将 ElementHost 的实例添加到 Windows 窗体中的容器控件(例如此处的 containerPanel)

    containerPanel.Controls.Add(elementHost);  

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);  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文