在svg插件中使用Xamarin中的scalabe svg文件 [英] Using scalabe svg files in Xamarin with the svg plugin

查看:119
本文介绍了在svg插件中使用Xamarin中的scalabe svg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Xamarin Forms插件SVG.Forms.Plugin.Abstractions呈现可缩放的SVG文件,而不是为每个设备大小创建一个文件.

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
            };

但是我宁愿在XAML中执行此操作,到目前为止,有以下内容

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"/>

我假设我需要在后面的代码中将SvgPath绑定到字符串值,但是我不确定将SvgAssembly绑定到什么,我尝试了一个字符串,但是它给出了未处理的运行时错误. 有人知道该怎么做吗?

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?

预先感谢

推荐答案

您应将其绑定到实际的程序集. 为简化起见,您可以从要查找的程序集内的类型中获取程序集:

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.

这篇关于在svg插件中使用Xamarin中的scalabe svg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆