Using scalabe svg files in Xamarin with the svg pl

2019-08-17 08:54发布

I'm trying to use Xamarin Forms plugin SVG.Forms.Plugin.Abstractions to render scalable SVG files rather than create a file for each device size.

On reading the how-to, it states that to create the image in code I should do this:

new SvgImage
            {
                SvgPath = "pic.svg",
                SvgAssembly = typeof (App).GetTypeInfo().Assembly,
                HeightRequest = 200,
                WidthRequest = 200,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.End,
                BackgroundColor = Color.White
            };

However I would rather do this in XAML, and so far have the following

<abstractions:SvgImage Grid.Row="1" Grid.Column="0" SvgAssembly="{Binding SvgAssembly}" SvgPath="{Binding SvgPath}" HeightRequest="250" WidthRequest="250" BackgroundColor="White" HorizontalOptions="Center" VerticalOptions="End"/>

I assume I need to bind SvgPath to a string value in the code behind, but I'm not sure what to bind the SvgAssembly to, I tried a string but it gave an unhandled runtime error. Does anyone know how to do this?

thanks in advance

1条回答
再贱就再见
2楼-- · 2019-08-17 09:27

You should bind it to an actual assembly. To simplify, you could just get the assembly from a type that is within the assembly you are looking:

Assembly SvgAssembly = typeof(ClassInAssembly).Assembly;

You should be good to go with this.

If you need to dig a bit deeper, check out my blog post about drawing SVG with SkiaSharp.

查看更多
登录 后发表回答