【问题标题】:Using SVG images in Xamarin Forms在 Xamarin Forms 中使用 SVG 图像
【发布时间】:2017-12-17 20:49:43
【问题描述】:

我正在使用 nugget 包 SVG.Forms.Plugin.Abstractions,我从一个简单的示例中复制了下面的 XAML,但无法显示 SVG。

图像位于“TestApp”应用程序的“图像”文件夹中,其构建操作是“嵌入式资源”。 SvgAssebly 绑定到 viewModel 下面的公共程序集。

我得到的只是一个空白屏幕,顶部有标题文本。
任何人都可以看到明显的错误吗?

public Assembly SvgAssembly
{
       get { return typeof(App).GetTypeInfo().Assembly; }
}

XAML:

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="TestApp.MainPage" 
             xmlns:artina="clr-namespace:UXDivers.Artina.Shared;assembly=UXDivers.Artina.Shared" 
             xmlns:local="clr-namespace:TestApp;assembly=TestApp" Title="{ artina:Translate PageTitle}" BackgroundColor="{DynamicResource BasePageColor}"
             xmlns:abstractions="clr-namespace:SVG.Forms.Plugin.Abstractions;assembly=SVG.Forms.Plugin.Abstractions">

    <ContentPage.Content>

        <StackLayout>
            <abstractions:SvgImage
                SvgAssembly="{Binding SvgAssembly }"
                SvgPath="TestApp.images.brand.svg"
                Width="200"
                Height="200" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

【问题讨论】:

  • 你关注什么设备平台?

标签: xaml xamarin svg xamarin.forms


【解决方案1】:

请注意:

  1. 从绑定中删除间距:

    SvgAssembly="{绑定 SvgAssembly }"

  2. 您应该像这样引用图像:

    SvgPath="brand.SVG"

您需要确保正确引用图像: 我对另一个问题的回答here.

【讨论】:

    【解决方案2】:

    尝试使用 FFImageLoading,因为它可以选择使用 SVG 图像。它还可以选择在用户设备上缓存图像。查找以下文档:

    https://github.com/luberda-molinet/FFImageLoading/wiki/Xamarin.Forms-API

    【讨论】:

      猜你喜欢
      • 2018-07-12
      • 2019-11-14
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多