Share via

SvgImageSource Class


Provides a source object for properties that use a Scalable Vector Graphics (SVG) source. You can define a SvgImageSource by using a Uniform Resource Identifier (URI) that references a SVG file, or by calling SetSourceAsync(IRandomAccessStream) and supplying a stream.

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 262144)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SvgImageSource : ImageSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 262144)]
public class SvgImageSource : ImageSource
Public Class SvgImageSource
Inherits ImageSource
Object IInspectable DependencyObject ImageSource SvgImageSource

Windows requirements

Device family
Windows 10 Creators Update (introduced in 10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v4.0)


Here's an example of how to set the source of an Image to a SVG file. Since there is no height or width explicitly specified, the application layout will dictate the appropriate size for the SVG to decode at.

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


SvgImageSource lets you use a SVG source to be displayed using an ImageBrush or directly in an Image control. SvgImageSource supports secure static mode from the SVG specification and does not support animations or interactions. The Direct2D API supplies the underlying SVG rendering support and for more info on specific SVG element and attribute support, see SVG Support. For more info on formats and how to use Uniform Resource Identifier (URI) to access image source files that come from app resources, see Image and ImageBrush.

The SvgImageSource represents an abstraction so that a SVG source can be set asynchronously but still be referenced in XAML markup as a property value, or in code as an object that doesn't use awaitable syntax. When you create a SvgImageSource object in code, it initially has no valid source. You should then set its source using one of these techniques:

  • Use the SvgImageSource(Uri) constructor rather than the default constructor. Although it's a constructor, you can think of this as having an implicit asynchronous behavior: the SvgImageSource won't be ready for use until it raises an Opened event that indicates a successful async source set operation.
  • Set the UriSource property. As with the Uri constructor, this action is implicitly asynchronous, and the SvgImageSource won't be ready for use until it raises an Opened event.
  • Use SetSourceAsync(IRandomAccessStream). This method is explicitly asynchronous. The properties where you might use a SvgImageSource, such as Source, are designed for this asynchronous behavior, and won't throw exceptions if they are set using a SvgImageSource that doesn't have a complete source yet. Rather than handling exceptions, you should handle Opened or OpenFailed events either on the SvgImageSource directly or on the control that uses the source (if those events are available on the control class).

Opened and OpenFailed are mutually exclusive. One event or the other will always be raised whenever a SvgImageSource object has its source value set or reset.


Depending on your intended use case, you can specify the size of a SvgImageSource in several different ways:

  • Use the RasterizePixelHeight and RasterizePixelWidth properties to specify an explicit height and width in logical pixels to decode the SVG source at.
  • If you don't specify a RasterizePixelHeight or RasterizePixelWidth, then the application's layout will dictate the decode size while still preserving aspect ratio. If no size can be determined from the application's layout, then the SVG source will be decoded to the maximum window size.

Version compatibility

The SvgImageSource class is not available prior to Windows 10, version 1703. If your app’s 'minimum platform version' setting in Microsoft Visual Studio is less than the 'introduced version' shown in the Requirements block later in this page, you will not be able to use SvgImageSource. For more info, see Version adaptive code.

To avoid exceptions when your app runs on previous versions of Windows 10, do not set this property in XAML or use it without performing a runtime check. This example shows how to use the ApiInformation class to check for the presence of this class before you use it.



Initializes a new instance of the SvgImageSource class.


Initializes a new instance of the SvgImageSource class, using the supplied Uniform Resource Identifier (URI).



Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.

(Inherited from DependencyObject)

Gets or sets the height to use for SVG rasterization operations.


Identifies the RasterizePixelHeight dependency property.


Gets or sets the width to use for SVG rasterization operations.


Identifies the RasterizePixelWidth dependency property.


Gets or sets the Uniform Resource Identifier (URI) of the SVG source file that generated this SvgImageSource.


Identifies the UriSource dependency property.



Clears the local value of a dependency property.

(Inherited from DependencyObject)

Returns any base value established for a dependency property, which would apply in cases where an animation is not active.

(Inherited from DependencyObject)

Returns the current effective value of a dependency property from a DependencyObject.

(Inherited from DependencyObject)

Returns the local value of a dependency property, if a local value is set.

(Inherited from DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance.

(Inherited from DependencyObject)

Sets the source SVG for a SvgImageSource by accessing a stream and processing the result asynchronously.

SetValue(DependencyProperty, Object)

Sets the local value of a dependency property on a DependencyObject.

(Inherited from DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback.

(Inherited from DependencyObject)



Occurs when the SVG source is downloaded and decoded with no failure.


Occurs when there is an error associated with SVG retrieval or format.

Applies to