Home

Awesome

XamaRed.Forms.Svg

XamaRed.Forms.Svg is simple SVG viewer control for Xamarin Forms. It is based on SkiaSharp.

Features

Download

This control is available as a Nuget package : XamaRed.Forms.Svg.

Usage

Namespace declaration :

xmlns:svg="clr-namespace:XamaRed.Forms.Svg;assembly=XamaRed.Forms.Svg"

Simple image display :

<svg:SvgView ResourceId="MyProject.Assets.myfile.svg" />

Image display with custom stretch mode and alignment :

<svg:SvgView ResourceId="MyProject.Assets.myfile.svg" VerticalAligment="Middle" HorizontalAligment="Middle" Stretch="UniformToFill" />

About stretch mode and alignment

The stretch modes are the same as in WPF :

The alignment values match the ones in Xamarin Forms :

Stretch and Horizontal/Vertical alignments should be used together in order to obtain the intended rendering.

StretchHorizontal alignmentVertical alignmentResult example
UniformStart(any)example1
UniformToFill(any)Endexample2
NoneMiddleMiddleexample3

Please check the included samples for more examples.

More advanced features

The assembly containing the SVG files will default to the Xamarin Forms application assembly. It is possible to override this behavior by setting the MainPclAssembly static property. In order to simplify the resource identifiers, it is also possible to set a default prefix which will be added in front of all identifiers of all SvgView instances. This is done through the ResourceIdsPrefix static property.

SvgView.ResourceIdsPrefix = "XamaRed.Forms.Svg.Tests.Assets.";
SvgView.MainPclAssembly = typeof(EnsurePictureTests).Assembly;
<svg:SvgView ResourceId="inkscape.svg" />

Limitations

The SVG support of Skia is currently limited to basic features. Advanced SVG files may not render correctly.

Update notes

v1.1.0 : Added .NET Standard 2.0 support (and requirement)