Border. The Border control in WPF provides a way to organize an interface into parts. We use Border to draw colored, visual borders within a Window.
Getting started. First create a WPF application. In the Toolbox, select Border and drag it to your window in the designer. We can then change attributes of the Border.
Example. This example shows some features of a Border. Here we change the Border attributes within the XAML file—here are some of the more useful properties.
Tip We can set the BorderBrush to a named color. In this example, I use a red color: Tomato.
Next The BorderThickness attribute indicates the number of pixels wide the border itself is.
Further We set the HorizontalAlignment and VerticalAlignment attributes to Stretch. These expand (anchor) the border to the container.
Example 2. Another element can be nested within a Border element. This means it is possible to use Border to create a section of user interface with sub-controls.
And By changing the positioning of these controls, we simplify our program layout.
Here We nested an "aqua" border within our "tomato" border. We use the simplified margin syntax. We set the thickness to 3.
A summary. We can add colors to Borders, adjust their thickness, and change their alignments—even stretch them. We can nest other controls within a Border.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.