1 下载Inkscape
2 用Inkscape打开svg,另存为xaml
注意:复杂的svg图转换完会出现类似下面的xaml,wpf/silverlight是无法解析的。
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path29231" StrokeThickness="1" Stroke="#FFFFFFFF" StrokeStartLineCap="Round" StrokeEndLineCap="Round" Opacity="1">
<Path.Data>
<PathGeometry Figures="M149 643 A7 7 0 1 0 156 651" FillRule="NonZero"/>
</Path.Data>
</Path>
你需要把它转换成如下的形式。
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path29231" StrokeThickness="1" Stroke="#FFFFFFFF" StrokeStartLineCap="Round" StrokeEndLineCap="Round" Opacity="1">
<Path.Data>M149 643 A7 7 0 1 0 156 651</Path.Data>
</Path>
只需要在XamlReader.Load之前对xamltext做下替换即可,例:
string xamltext= Regex.Replace(xamltext, @"(?<=<Path.Data>)(.+?Figures=""(.+?)"".+?)(?=</Path.Data>)", "$2");