Rectangle. Shapes can be part of WPF interfaces. With the Rectangle, we specify a rectangular graphical region that can have different colors and borders.
Getting started. First, please drag a Rectangle from the Visual Studio Toolbox to your WPF Window. Next, you can adjust its attributes.
Attributes example. 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.
Tip You can adjust the thickness of the Stroke (border) by adding a StrokeThickness attribute, which counts in pixels.
Tip 2 You can apply a colored background to the rectangle with the Fill attribute. This can receive hex colors or the named colors.
Finally You will need to adjust Width and Height as well. This will determine the size of the rectangle.
Summary. 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.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Sep 28, 2022 (edit).