O'Reilly logo

Windows Application Development Cookbook by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing shapes programmatically

As you have already seen in this chapter, basic shapes, such as rectangles, ellipses, or lines, can be defined declaratively in the XAML language. However, they can also be created programmatically using the C# language, as you will see in this recipe.

As an example, you will create a simple page with the Canvas control, where a rectangle, an ellipse, a polygon, a polyline, and a set of lines will be drawn.

Getting ready

To step through this recipe, you need only the automatically generated project.

How to do it...

To prepare the example that draws a rectangle, an ellipse, a polygon, a polyline, and a set of lines programmatically, perform the following steps:

  1. Add a canvas to the page by modifying the MainPage.xaml file, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required