Image Source Class
/// [Windows.Foundation.Metadata.Composable(Windows.UI.Xaml.Media.Imaging.ISvgImageSourceFactory, Windows.Foundation.Metadata.CompositionType.Public, 262144, "Windows.Foundation.UniversalApiContract")] /// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 262144)] /// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)] /// [Windows.Foundation.Metadata.Static(Windows.UI.Xaml.Media.Imaging.ISvgImageSourceStatics, 262144, "Windows.Foundation.UniversalApiContract")] /// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)] /// [Windows.Foundation.Metadata.WebHostHidden] class SvgImageSource : ImageSource
[Windows.Foundation.Metadata.Composable(typeof(Windows.UI.Xaml.Media.Imaging.ISvgImageSourceFactory), Windows.Foundation.Metadata.CompositionType.Public, 262144, "Windows.Foundation.UniversalApiContract")] [Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 262144)] [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)] [Windows.Foundation.Metadata.Static(typeof(Windows.UI.Xaml.Media.Imaging.ISvgImageSourceStatics), 262144, "Windows.Foundation.UniversalApiContract")] [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)] [Windows.Foundation.Metadata.WebHostHidden] public class SvgImageSource : ImageSource
Public Class SvgImageSource Inherits ImageSource
Windows 10 requirements
Windows 10 Creators Update (introduced in 10.0.15063.0)
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.
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).
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.
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)
Sets the source SVG for a SvgImageSource by accessing a stream and processing the result asynchronously.
Sets the local value of a dependency property on a DependencyObject.(Inherited from DependencyObject)
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.