Rectangle and RectangleGeometries WPF in VB.NET

In this article you will learn how to create Rectangle and RectangleGeometries "and what is the difference between them" in WPF.
  • 5119

Rectangle: The Rectangle is  the simplest shape. To create either one, set the familiar Height and Width properties (inherited from FrameworkElement) to define the size of your shape, and then set the Fill or Stroke property (or both) to make the shape visible. You're also free to use properties such as MinHeight, MinWidth, HorizontalAlignment, VerticalAlignment, and Margin.

Example of an Rectangle

<Window x:Class="Window1"
    Title="Window1" Height="300" Width="300">
    <Rectangle Fill="Yellow" Stroke="Blue"
Height="60" Width="110" Margin="6" HorizontalAlignment="Center"></Rectangle>

Output Window



RectangleGeometries: The only real difference is that the Rectangle shape takes Height and Width values, while the RectangleGeometry takes four numbers that describe the size and location of the rectangle. The first two numbers describe the X and Y coordinates point where the top-left corner will be placed, while the last two numbers set the width and height of the rectangle. You can start the rectangle out at (0, 0) to get the same effect as an ordinary Rectangle element, or you can offset the rectangle using different values. The RectangleGeometry class also includes the RadiusX and RadiusY properties that let you round the corners.

Example of an RectangleGeometries

<Window x:Class="Window1"
    Title="Window1" Height="300" Width="300">
    <Path Fill="Blue" Stroke="Yellow">
            <RectangleGeometry Rect="50,50,125,60">

Output Window




I hope this article help you to understands the difference and the working of  Rectangle and RectangleGeometries in WPF.


More Articles

© 2020 DotNetHeaven. All rights reserved.