Home > Net >  Is there a way to render svg files in UWP
Is there a way to render svg files in UWP

Time:01-25

I need to render complex svg files in my UWP application, but I haven't found any way to properly render a svg file from a path without using a WebView.

Is there a library which is able to do that? Moreover it would be great if it provides DataBinding.

With complex I mean every valid svg file should be able to render properly. e.g. a base64 encoded image within the svg file

Currently I use a WebView but there are a few caveats:

  • kinda slow. it takes approximately a second to load. I'd expect at most 500ms (I think that's possible)
  • I have to know the size of the file in advance
  • there are sometimes clipping issues
  • I use it inside a scroll view with the ability to zoom and sometimes something breaks and weird things happen
  • I have to cover the web view with another view and forward the events to the ScrollView (not very MVVM friendly)

CodePudding user response:

Is there a way to render svg files in UWP

Sure, please refer SvgImageSource document, it could used to render svg image file. You can define a SvgImageSource by using a Uniform Resource Identifier (URI) that references a SVG file.

For example

<Image
    Width="24"
    Height="24"
    Stretch="Fill">
    <Image.Source>
        <SvgImageSource  
            UriSource="/Assets/AddComment.svg" />
    </Image.Source>
</Image>

And you could also use Win2D library to render SVG file, this related care reply that you could refer to.

  •  Tags:  
  • Related