Rectangle
Shapes can be part of WPF interfaces. With the Rectangle
, we specify a rectangular graphical region that can have different colors and borders.
First, please drag a Rectangle
from the Visual Studio Toolbox to your WPF Window. Next, you can adjust its attributes.
By dragging some of the guides, you can add a RadiusY
and RadiusX
: these give the rectangle rounded corners. Next, try adding the Stroke attribute in the XAML.
StrokeThickness
attribute, which counts in pixels.<Window x:Class="WpfApplication16.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"> <Grid> <Rectangle Fill="Beige" HorizontalAlignment="Left" Height="100" Margin="10,10,0,0" Stroke="DarkMagenta" StrokeThickness="5" VerticalAlignment="Top" Width="150" RadiusY="13.5" RadiusX="13.5"/> </Grid> </Window>
With the RadiusX
and RadiusY
attributes, you can create an Ellipse with a rectangle. But using an Ellipse control directly may be simpler.
With WPF, a main goal is to make programs easier and faster to create. The Rectangle
control help this goal: they are easy options for when a graphical element (shape) is needed.