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.
To prepare the example that draws a rectangle, an ellipse, a polygon, a polyline, and a set of lines programmatically, perform the following steps:
Add a canvas to the page by modifying the
MainPage.xaml
file, as follows:<Page (...)> <Grid> <Canvas x:Name="Canvas" /> </Grid> </Page>
Prepare a method to draw a green rectangle (of size 100 x 100 pixels with rounded...