Svg Source Image
Svg Source Image
Svg Source Image
public : class SvgImageSource : ImageSource, ISvgImageSource
struct winrt::Windows::UI::Xaml::Media::Imaging::SvgImageSource : ImageSource, ISvgImageSource
public class SvgImageSource : ImageSource, ISvgImageSource
Public Class SvgImageSource Inherits ImageSource Implements ISvgImageSource
Windows 10 requirements
Windows 10 Creators Update (introduced v10.0.15063.0)
Windows.Foundation.UniversalApiContract (introduced v4)
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(svgimagesource.md) 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).
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.
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.
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.
|SvgImageSource() SvgImageSource() SvgImageSource() SvgImageSource()||
Initializes a new instance of the SvgImageSource class.
|SvgImageSource(Uri) SvgImageSource(Uri) SvgImageSource(Uri) SvgImageSource(Uri)||
Initializes a new instance of the SvgImageSource class, using the supplied Uniform Resource Identifier (URI).
|Opened Opened Opened Opened||
Occurs when the SVG source is downloaded and decoded with no failure.
|OpenFailed OpenFailed OpenFailed OpenFailed||
Occurs when there is an error associated with SVG retrieval or format.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.