Click or drag to resize
CanvasSvgDocument Class
[Win10_15063] Specifies an SVG document that can be drawn.
Inheritance Hierarchy
SystemObject
  Microsoft.Graphics.Canvas.SvgCanvasSvgDocument

Namespace:  Microsoft.Graphics.Canvas.Svg
Assembly:  Microsoft.Graphics.Canvas (in Microsoft.Graphics.Canvas.dll) Version: 0.0.0.0
Syntax
C#
public sealed class CanvasSvgDocument : IDisposable

The CanvasSvgDocument type exposes the following members.

Constructors
  NameDescription
Public methodCanvasSvgDocument
[Win10_15063] Initializes a new instance of the CanvasSvgDocument class.
Top
Properties
  NameDescription
Public propertyDevice
[Win10_15063] Gets the device associated with this SVG document.
Public propertyRoot
[Win10_15063] Gets or sets the root element of the SVG document.
Top
Methods
  NameDescription
Public methodCreatePaintAttribute
[Win10_15063] Creates an attribute that can be used for a stroke or fill value.
Public methodCreatePaintAttribute(CanvasSvgPaintType, Color, String)
[Win10_15063] Creates an attribute that can be used for a stroke or fill value.
Public methodCreatePathAttribute
[Win10_15063] Creates an attribute that can be used for path data, for example on the 'd' attribute of a 'path' element.
Public methodCreatePathAttribute(Single, CanvasSvgPathCommand)
[Win10_15063] Creates an attribute that can be used for path data, for example on the 'd' attribute of a 'path' element.
Public methodCreatePointsAttribute
[Win10_15063] Creates an attribute that can be used to describe a collection of points, for example in a polyline or polygon element.
Public methodCreatePointsAttribute(Vector2)
[Win10_15063] Creates an attribute that can be used to describe a collection of points, for example in a polyline or polygon element.
Public methodCreateStrokeDashArrayAttribute
[Win10_15063] Creates an attribute that can be used as a stroke-dasharray vlalue.
Public methodCreateStrokeDashArrayAttribute(Single, CanvasSvgLengthUnits)
[Win10_15063] Creates an attribute that can be used as a stroke-dasharray vlalue.
Public methodDispose
[Win10_15063] Releases all resources used by the CanvasSvgDocument.
Public methodFindElementById
[Win10_15063] Finds the element in this document which has the specified ID.
Public methodGetXml
[Win10_15063] Gets a string containing the SVG for this document.
Public methodStatic memberIsSupported
[Win10_15063] Checks whether CanvasSvgDocument is supported on the current operating system version.
Public methodStatic memberLoadAsync
[Win10_15063] Loads an SVG document from a stream.
Public methodLoadElementAsync
[Win10_15063] Loads an SVG element from a stream containing an XML fragment.
Public methodLoadElementFromXml
[Win10_15063] Loads an SVG element from string containing an XML fragment.
Public methodStatic memberLoadFromXml
[Win10_15063] Loads an SVG document from a string.
Public methodSaveAsync
[Win10_15063] Saves a string containing the SVG for this document.
Top
Remarks

This API is only available when running on Windows 10 build 15063 (Creators Update) or greater.

To draw SVG, first create a document using Load or LoadAsync. Then, draw it to a drawing session using DrawSvg. For example, in C#,

C#
using Microsoft.Graphics.Canvas.Svg;     

CanvasSvgDocument svgDocument;

void canvasControl_CreateResources(CanvasControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
{
    svgDocument = CanvasSvgDocument.LoadFromXml(sender, "<svg><circle fill=\"#660000\" r=\"500\"/></svg>");
}

void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
    args.DrawingSession.DrawSvg(svgDocument, sender.Size);
}
It's recommended that apps load their SVG resources only once, rather than every time they are drawn.

In addition to being drawn directly, SVG can also be used as an image- for example, to used as source for an image brush, or an input to an effect. To do this, use a command list. For example, in C#:

C#
void canvasControl_Draw(CanvasControl sender, CanvasDrawEventArgs args)
{
    CanvasCommandList commandList = new CanvasCommandList(sender);

    using (var ds = commandList.CreateDrawingSession())
    {
        ds.DrawSvg(svgDocument, sender.Size);
    }

    OpacityEffect opacityEffect = new OpacityEffect();
    opacityEffect.Opacity = 0.5f;
    opacityEffect.Source = commandList;

    args.DrawingSession.DrawImage(opacityEffect);
}
If your application may run on operating systems prior to Windows 10 Creators Edition, it should call CanvasSvgDocument.IsSupported to query whether SVG is supported before using it.

Currently, Win2D supports a subset of SVG 1.1. For more details, see Direct2D's page about SVG support.

See Also