WPF draws borders by border

Source: Internet
Author: User

WPF has its own table control, the DataGrid, the ListBox, and so on, and if it's just a simple requirement, you can draw a border through the border control.

For example, we need to add a border to the above controls.

<window x:class="Wpfapplication5.mainwindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"XMLNS:MC="http://schemas.openxmlformats.org/markup-compatibility/2006"Xmlns:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"Xmlns:dxcore="Http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:local="Clr-namespace:wpfapplication5"mc:ignorable="D"Title="MainWindow"height=" -"Width="525"> <Window.Resources> <ResourceDictionary> <local:changevaluetoresult x:key="Changevaluetoresult"></local:ChangeValueToResult> <ResourceDictionary.MergedDictionaries> &LT;RESOURC Edictionary source="Style/test.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </window.resource s> <Grid> <Grid.RowDefinitions> <rowdefinition height="50*"/> <rowdefinition height="60*"/> <rowdefinition height="73*"/> <rowdefinition height="46*"/> <rowdefinition height="52*"/> <rowdefinition height="39*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <columndefinition width="91*"/> <columndefinition width="96*"/> <columndefinition width="105*"/> <columndefinition width="101*"/> <columndefinition width="124*"/> </Grid.ColumnDefinitions> <border grid.row="0"grid.column="1"grid.rowspan="3"grid.columnspan="2"Borderbrush="Chocolate"borderthickness="1"/> <border grid.row="0"grid.column="1"grid.rowspan="3"grid.columnspan="1"Borderbrush="Chocolate"borderthickness="0,0,1, 0"/> <border grid.row="0"grid.column="1"grid.rowspan="1"grid.columnspan="2"Borderbrush="Chocolate"borderthickness="0,0,0, 1"/> <border grid.row="1"grid.column="1"grid.rowspan="1"grid.columnspan="2"Borderbrush="Chocolate"borderthickness="0,0,0, 1"/> <border grid.row="2"grid.column="1"grid.rowspan="1"grid.columnspan="2"Borderbrush="Chocolate"borderthickness="0,0,0, 1"/> <textblock grid.row="0"grid.column="1"text="first row, second column"/> <textblock grid.row="1"grid.column="1"text="Second row, second column"/> <textblock grid.row="2"grid.column="1"text="third row, second column"/> <textblock grid.row="0"grid.column="2"text="first row, third column"/> <textblock grid.row="1"grid.column="2"text="second row, third column"/> <textblock grid.row="2"grid.column="2"text="Third row, third column"/> </Grid></Window>

So we get this effect:

The code is relatively simple, the main want to explain the next border BorderThickness property.

borderthickness= "1", give borderthickness only one value, this time border, the thickness of the upper and lower borders is 1.
If you don't want to show which side, set the side thickness to 0. such as borderthickness= "0,0,1, 0", this time left, up and down will not show, only the right side will be displayed.

WPF draws borders by border

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.