WPF通过Border来画边框
WPF有⾃⼰的表格控件DataGrid、ListBox等,如果只是简单的需求,可以通过Border控件来画边框。
⽐如我们需要给上⾯的控件加上边框。
<Window x:Class="WpfApplication5.MainWindow"
xmlns="schemas.microsoft/winfx/2006/xaml/presentation"
xmlns:x="schemas.microsoft/winfx/2006/xaml"
xmlns:d="schemas.microsoft/expression/blend/2008"
xmlns:mc="/markup-compatibility/2006"
xmlns:dxdo="schemas.devexpress/winfx/2008/xaml/docking"
xmlns:dxcore="schemas.devexpress/winfx/2008/xaml/core"
xmlns:local="clr-namespace:WpfApplication5"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<local:ChangeValueToResult x:Key="changeValueToResult"></local:ChangeValueToResult>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Style/test.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
borderbox<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="第⼀⾏第⼆列"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="第⼆⾏第⼆列"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="第三⾏第⼆列"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="第⼀⾏第三列"/>
<TextBlock Grid.Row="1" Grid.Column="2" Text="第⼆⾏第三列"/>
<TextBlock Grid.Row="2" Grid.Column="2" Text="第三⾏第三列"/>
</Grid>
</Window>
这样我们就得到这样的效果:
代码⽐较简单,主要想说明下Border的BorderThickness属性。
BorderThickness="1",给BorderThickness只赋值⼀个值,这时候Border,上下左右边框的粗细都是1。
如果不想显⽰哪⼀边,就把那⼀边粗细设置为0.如BorderThickness="0,0,1, 0",这时候左、上、下都不会显⽰,只有右边才会显⽰。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论