Silverlight Ellipse Control
This article demonstrates how to create and use an Ellipse control in Silverlight using XAML and C#.
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 a 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 a Ellipse
The Ellipse element represents a Silverlight Ellipse control in XAML.
<Ellipse/>
The code snippet in Listing 1 creates an Ellipse by setting its width and height properties to 200 and 100 respectively. The code also sets the black stroke of width 4.
<Ellipse
Width="200"
Height="100"
Fill="Blue"
Stroke="Black"
StrokeThickness="4" />
Listing 1
The output looks like Figure 1.
Figure 1
The CreateAnEllipse method listed in Listing 2 draws same Ellipse in Figure 1 dynamically.
/// <summary>
/// Creates a blue Ellipse with black border
/// </summary>
public void CreateAnEllipse()
{
// Create a Ellipse
Ellipse blueEllipse = new Ellipse();
blueEllipse.Height = 100;
blueEllipse.Width = 200;
// Create a blue and a black Brush
SolidColorBrush blueBrush = new SolidColorBrush();
blueBrush.Color = Colors.Blue;
SolidColorBrush blackBrush = new SolidColorBrush();
blackBrush.Color = Colors.Black;
// Set Ellipse's width and color
blueEllipse.StrokeThickness = 4;
blueEllipse.Stroke = blackBrush;
// Fill Ellipse with blue color
blueEllipse.Fill = blueBrush;
// Add Ellipse to the Grid.
LayoutRoot.Children.Add(blueEllipse);
}
Listing 2
If we create an ellipse with an equal width and height, it will create a circle. The following code snippet creates a circle that looks like Figure 2.
<Ellipse
Width="200"
Height="100"
Fill="Blue"





jigar patelPosted May 25, 2010, 7:15 AM
thnx man .. ur tutorial are always helpful for me.............................