该教程主要时通过第三方组件Svg2Xaml(https://github.com/smischke/svg2xaml)来加载svg资源到图片控件(Image)中。
官方:svg2Xaml主要的使用方式为:
using (FileStream stream = newFileStream(FileName, FileMode.Open, FileAccess.Read))
{
DrawingImage image = SvgReader.Load(stream);
}
Further more you may use the SvgImage markup extension:
< !--xmlns:svg2xaml = "clr-namespace:Svg2Xaml;assembly=Svg2Xaml"-- >
< ImageSource = "{svg2xaml:SvgImage test.svg}" />
我这里整合上边的方式封装了一个更加简便的调用方式。主要的思路为在转换器中做转换,在界面中直接绑定图片的Source,将图片路径作为参数进行传递。
主要代码:
![](https://img.haomeiwen.com/i13423228/e5033677c24d48c3.png)
![](https://img.haomeiwen.com/i13423228/4541b605ad57a0dd.png)
效果图:
![](https://img.haomeiwen.com/i13423228/4408373005ae5168.png)
网友评论