The Ellipse object represents an ellipse shape and draws an ellipse with the given height and width. The Width and Height properties of the Ellipse class represent the width and height of an ellipse. The Fill property fills the interior of an ellipse. The Stroke property sets the color and StrokeThickness represents the width of the outer line of an ellipse.
Creating an Ellipse
The Ellipse element in XAML creates an ellipse shape. The following code snippet creates an ellipse by setting its width and height properties to 200 and 100 respectively. The code also sets the black stroke of width to four.
- <Ellipse
- Width="200"
- Height="100"
- Fill="Blue"
- Stroke="Black"
- StrokeThickness="4" />
The output looks like Figure 7.
Figure 7. An Ellipse
The CreateAnEllipse method listed in Listing 8 draws the same rectangle in Figure 7 dynamically.
-
-
-
- public void CreateAnEllipse() {
-
- Ellipse blueRectangle = new Ellipse();
- blueRectangle.Height = 100;
- blueRectangle.Width = 200;
-
- SolidColorBrush blueBrush = new SolidColorBrush();
- blueBrush.Color = Colors.Blue;
- SolidColorBrush blackBrush = new SolidColorBrush();
- blackBrush.Color = Colors.Black;
-
- blueRectangle.StrokeThickness = 4;
- blueRectangle.Stroke = blackBrush;
-
- blueRectangle.Fill = blueBrush;
-
- LayoutRoot.Children.Add(blueRectangle);
- }
Listing 7
A circle is an ellipse with an equal width and height. If you set both width and height to 200 in the above code listed in Listing 7, it will generate a circle.