Wpf 将SVG转换为XAML

Wpf 将SVG转换为XAML,wpf,xaml,Wpf,Xaml,我知道这个问题已经得到了回答,因为我已经按照这些答案的说明进行了回答。我有一个图标的.SVG图像,我试图将其转换为可用的XAML代码,我使用的图像如下 <ControlTemplate x:Uid="ControlTemplate_9" x:Key="IconTemplate"> <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">

我知道这个问题已经得到了回答,因为我已经按照这些答案的说明进行了回答。我有一个图标的.SVG图像,我试图将其转换为可用的XAML代码,我使用的图像如下

<ControlTemplate x:Uid="ControlTemplate_9" x:Key="IconTemplate">
  <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
    <Canvas Name="svg2" Width="24" Height="16" ToolTip="IconToolTip.">
      <Canvas.RenderTransform>
        <TranslateTransform X="0" Y="0"/>
      </Canvas.RenderTransform>
      <Canvas.Resources/>
      <Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path16" Fill="#FFFCF0F0">
        <Path.Data>
          <PathGeometry Figures=" M 22.30" FillRule="NonZero"/>
        </Path.Data>
      </Path>
    </Canvas>
  </Viewbox>
</ControlTemplate>

当我开始使用这个系统时,大多数已经提供了,但我的问题是增加了更多。当使用Inkscape或printing to PDF等程序并打开.fpage文件时,我得到的.XAML大致如下:-

<?xml version="1.0" encoding="UTF-8"?>
<!--This file is NOT compatible with Silverlight-->
<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
    <Canvas Name="svg2" Width="24" Height="16">
        <Canvas.RenderTransform>
            <TranslateTransform X="0" Y="0"/>
        </Canvas.RenderTransform>
        <Canvas.Resources/>
        <!--Unknown tag: metadata-->
        <!--Unknown tag: sodipodi:namedview-->
        <Rectangle xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="24" Height="16" RadiusX="4" RadiusY="4" Name="Rounded_Rectangle_1" Fill="#000000"/>
        <Rectangle xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Left="11" Canvas.Top="3" Width="2" Height="6" Name="rect9" Fill="#000000"/>
        <Image xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="image11" Canvas.Left="11" Canvas.Top="11" Source="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQAAAABazTCJAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAHdElNRQfgCRoPHAwMuTLjAAAADElEQVQI12M4wHAAAAMEAYHFO6KpAAAAAElFTkSuQmCC" Width="2" Height="2"/>
    </Canvas>
</Viewbox>


后者将不会编译并导致程序崩溃。因此,我对前面问题的扩展是,我如何在代码库中使用后一个XAML,而不直接在项目文件夹中使用图像,或者如何将其转换为可用的路径数据。

我所做的,实际上工作得很好的是删除所有xml部分:

<Viewbox Stretch="Uniform">
  <Canvas Name="svg2" Width="24" Height="16">
    <Canvas.RenderTransform>
        <TranslateTransform X="0" Y="0"/>
    </Canvas.RenderTransform>
    <Canvas.Resources/>
    <Rectangle Width="24" Height="16" RadiusX="4" RadiusY="4" Name="Rounded_Rectangle_1" Fill="#000000"/>
    <Rectangle Canvas.Left="11" Canvas.Top="3" Width="2" Height="6" Name="rect9" Fill="#000000"/>
    <Image Name="image11" Canvas.Left="11" Canvas.Top="11" Source="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQAAAABazTCJAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAHdElNRQfgCRoPHAwMuTLjAAAADElEQVQI12M4wHAAAAMEAYHFO6KpAAAAAElFTkSuQmCC" Width="2" Height="2"/>
  </Canvas>
</Viewbox>

我已经将它们添加到ResourceDictionary中,以便可以在整个项目中使用它们

<Viewbox x:Key="MyIcon" x:Shared="False" Stretch="Uniform">
  <Canvas Name="svg2" Width="24" Height="16">
    <Canvas.RenderTransform>
        <TranslateTransform X="0" Y="0"/>
    </Canvas.RenderTransform>
    <Canvas.Resources/>
    <Rectangle Width="24" Height="16" RadiusX="4" RadiusY="4" Name="Rounded_Rectangle_1" Fill="#000000"/>
    <Rectangle Canvas.Left="11" Canvas.Top="3" Width="2" Height="6" Name="rect9" Fill="#000000"/>
    <Image Name="image11" Canvas.Left="11" Canvas.Top="11" Source="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQAAAABazTCJAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAACxIAAAsSAdLdfvwAAAAHdElNRQfgCRoPHAwMuTLjAAAADElEQVQI12M4wHAAAAMEAYHFO6KpAAAAAElFTkSuQmCC" Width="2" Height="2"/>
  </Canvas>
</Viewbox>