rsp
rsp

Reputation: 649

How to use svg image file in XAML Image component

I am trying to use svg to display an illustration on uwp app. I am creating BitmapImage object using svg like below

m_imageSource = Windows::UI::Xaml::Media::Imaging::BitmapImage(Windows::Foundation::Uri{ GetFilePath() + L"FamilyValueProp\\Assets\\Images\\family_promo.svg"});

And setting this source to Image component

<Image x:Name="PromoImage" Source="{x:Bind ViewModel.ImageSource, Mode=OneWay}" />

But this does not render the image. Image is present in the path that is provided to BitmapImage object. Not sure what is going wrong. Any help please?

Upvotes: 1

Views: 2395

Answers (1)

Shawn Kendrot
Shawn Kendrot

Reputation: 12465

You will want to use the SvgImageSource if creating an ImageSource.

m_imageSource = new SvgImageSource(new Uri("mySvgImage.svg"));

You can also set the svg directly to the Image

<Image Source="Assets/mysvg.svg"/>

Note that animations are not supported

SvgImageSource supports secure static mode from the SVG specification and does not support animations or interactions

Upvotes: 3

Related Questions