如何將svg轉換為xaml
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");