CanvasSvgDocument Class |
Namespace: Microsoft.Graphics.Canvas.Svg
public sealed class CanvasSvgDocument : IDisposable
The CanvasSvgDocument type exposes the following members.
Name | Description | |
---|---|---|
CanvasSvgDocument | [Win10_15063] Initializes a new instance of the CanvasSvgDocument class. |
Name | Description | |
---|---|---|
Device | [Win10_15063] Gets the device associated with this SVG document. | |
Root | [Win10_15063] Gets or sets the root element of the SVG document. |
Name | Description | |
---|---|---|
CreatePaintAttribute | [Win10_15063] Creates an attribute that can be used for a stroke or fill value. | |
CreatePaintAttribute(CanvasSvgPaintType, Color, String) | [Win10_15063] Creates an attribute that can be used for a stroke or fill value. | |
CreatePathAttribute | [Win10_15063] Creates an attribute that can be used for path data, for example on the 'd' attribute of a 'path' element. | |
CreatePathAttribute(Single, CanvasSvgPathCommand) | [Win10_15063] Creates an attribute that can be used for path data, for example on the 'd' attribute of a 'path' element. | |
CreatePointsAttribute | [Win10_15063] Creates an attribute that can be used to describe a collection of points, for example in a polyline or polygon element. | |
CreatePointsAttribute(Vector2) | [Win10_15063] Creates an attribute that can be used to describe a collection of points, for example in a polyline or polygon element. | |
CreateStrokeDashArrayAttribute | [Win10_15063] Creates an attribute that can be used as a stroke-dasharray vlalue. | |
CreateStrokeDashArrayAttribute(Single, CanvasSvgLengthUnits) | [Win10_15063] Creates an attribute that can be used as a stroke-dasharray vlalue. | |
Dispose | [Win10_15063] Releases all resources used by the CanvasSvgDocument. | |
FindElementById | [Win10_15063] Finds the element in this document which has the specified ID. | |
GetXml | [Win10_15063] Gets a string containing the SVG for this document. | |
IsSupported | [Win10_15063] Checks whether CanvasSvgDocument is supported on the current operating system version. | |
LoadAsync | [Win10_15063] Loads an SVG document from a stream. | |
LoadElementAsync | [Win10_15063] Loads an SVG element from a stream containing an XML fragment. | |
LoadElementFromXml | [Win10_15063] Loads an SVG element from string containing an XML fragment. | |
LoadFromXml | [Win10_15063] Loads an SVG document from a string. | |
SaveAsync | [Win10_15063] Saves a string containing the SVG for this document. |
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#,
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); }
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#:
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); }
Currently, Win2D supports a subset of SVG 1.1. For more details, see Direct2D's page about SVG support.