WPF: Creating ellipse or rectangle using canvas

Using WPF, we can create ellipse or rectangle using XAML canvas.

The following example create a red ellipse and a blue rectangle.

MainWindow.xaml
<Window x:Class="Ellipse.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Canvas>
        <Ellipse Fill="Red" Width="100" Height="60" />
        <Rectangle Fill="Blue" Width="80" Height="80" Canvas.Left="100" Canvas.Top="100" />
        <Button Content="Hello" Canvas.Left="130" Canvas.Top="30" FontSize="20" />
    </Canvas>
</Window>

The output from running the above code is:

ellipse

 

Series Navigation<< WPF: Accessing attached properties
WPF: Creating overlapping rectangles using canvas >>