TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to WPF

WPF Rectangle: Fill and Stroke

Rectangle. Shapes can be part of WPF interfaces. With the Rectangle, we specify a rectangular graphical region that can have different colors and borders. This improves the interfaces of some programs.
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.

Stroke: Next, try adding the Stroke attribute in the XAML. You will need to manually specify this in the markup.

StrokeThickness: You can adjust the thickness of the Stroke (border) by adding a StrokeThickness attribute, which counts in pixels.

Also, you can apply a colored background to the rectangle with the Fill attribute. This can receive hex colors or the named colors in Visual Studio's list. You will need to adjust Width and Height as well.
Example markup: XAML <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>
Ellipse. With the RadiusX and RadiusY attributes, you can create an Ellipse with a rectangle. But using an Ellipse control directly may be simpler. I cover Ellipse in a separate example page.

Tip: In the Ellipse example, I show how mouse events can interact with shapes. This is equally true with rectangles.

Summary. With WPF, a main goal is to make programs easier and faster to create. The Rectangle control (and similar controls like Ellipse) help this goal: they are easy options for when a graphical element (shape) is needed.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf