wpf 如何在网格中设置列的右边框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21242907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set Right Border of a Column in a Grid?
提问by Dzyann
I have a Grid like this:
我有一个像这样的网格:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0">Row 0, Column 1</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0">Row 1, Column 1</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">Row 2, Column 1</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="0">Row 3, Column 1</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Grid.RowSpan="4">Column 1</TextBlock>
</Grid>
I am not going to actually use TexBlocks in the real application, I used them to make the example easier. Basically I want to Set the border that devides all the content in Column 0 from Column 1.
我不会在实际应用程序中实际使用 TexBlocks,我使用它们使示例更容易。基本上我想设置将第 0 列中的所有内容与第 1 列分开的边框。
How do you do that?
你是怎样做的?
回答by Sheridan
One of the best ways to display a Borderis to use a Borderelement. You can just declare it behindthe other content:
显示 a 的最佳方法之一Border是使用Border元素。您可以将其声明在其他内容后面:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Border Grid.Column="1" Grid.RowSpan="4" BorderBrush="Black"
BorderThickness="1,0,0,0" Background="{x:Null}" />
<TextBlock Grid.Row="0" Grid.Column="0">Row 0, Column 1</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0">Row 1, Column 1</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">Row 2, Column 1</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="0">Row 3, Column 1</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Grid.RowSpan="4">Column 1</TextBlock>
</Grid>
回答by Chris W.
There's a number of ways to accomplish it, easiest, just draw a line (except I cheated and used a shape...I know, horrible of me right? But you get the idea..) Hope this helps.
有很多方法可以完成它,最简单的方法是画一条线(除了我作弊并使用了形状......我知道,我很可怕吧?但你明白了......)希望这会有所帮助。
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Rectangle Grid.RowSpan="4" Width="1" Fill="Red" HorizontalAlignment="Right"/>
<TextBlock Grid.Row="0" Grid.Column="0">Row 0, Column 1</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0">Row 1, Column 1</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0">Row 2, Column 1</TextBlock>
<TextBlock Grid.Row="3" Grid.Column="0">Row 3, Column 1</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Grid.RowSpan="4">Column 1</TextBlock>
</Grid>

