Win2D 0.0.12 – geometry paths

Win2D version 0.0.12 is now available on NuGet and Github.

New this sprint:

  • CanvasAnimatedControl  improvements
    • Paused state works better than before
    • Restart the render thread less often
    • TDR recovery now works
    • Trim call (on app suspend) is now properly threadsafe
  • Memory management fixes
    • Removed a refcount cycle that was preventing our XAML controls ever being freed
    • Fixed a bunch of instance lifecycle and destructor-not-on-UI-thread issues that fell out as a result of now actually destroying our controls


Check out the backlog to see what we’ll be working on next  (ok, I’ll tell you here: it’s more geometry features, custom font loading, and layers).



A geometry is an arbitrarily complex 2D area.  It can be created from any number of lines:

var pathBuilder = new CanvasPathBuilder(sender);

pathBuilder.BeginFigure(new Vector2(10, 10));
pathBuilder.AddLine(30, 80);
pathBuilder.AddLine(50, 30);
pathBuilder.AddLine(70, 80);
pathBuilder.AddLine(90, 10);

pathBuilder.BeginFigure(new Vector2(105, 30));
pathBuilder.AddLine(105, 80);

And bezier curves:

pathBuilder.BeginFigure(new Vector2(160, 80));
pathBuilder.AddQuadraticBezier(new Vector2(148, 0), new Vector2(130, 80));
pathBuilder.AddLine(130, 40);

pathBuilder.BeginFigure(new Vector2(190, 10));
pathBuilder.AddCubicBezier(new Vector2(270, 0), new Vector2(210, 55), new Vector2(190, 80));
pathBuilder.AddLine(235, 80);

And arc segments:

pathBuilder.BeginFigure(new Vector2(255, 10));
pathBuilder.AddArc(new Vector2(255, 80), 30, 36, 0, CanvasSweepDirection.Clockwise, CanvasArcSize.Large);

After the desired figures have been added to a CanvasPathBuilder object, it is converted to a CanvasGeometry:

 var geometry = CanvasGeometry.CreatePath(pathBuilder);

The FillGeometry method can be used to fill the inside of a geometry with any brush, or DrawGeometry to draw its path using any stroke width and stroke style.  For instance:

var strokeStyle = new CanvasStrokeStyle
DashStyle = CanvasDashStyle.Dot,
DashCap = CanvasCapStyle.Round,
StartCap = CanvasCapStyle.Round,
EndCap = CanvasCapStyle.Round,
LineJoin = CanvasLineJoin.Bevel,

drawingSession.DrawGeometry(geometry, Colors.Black, 4, strokeStyle);



Comments (1)

  1. The Grand User says:

    Woot! good to see this in 😀

Skip to main content