在WP7中设置网格边框
我正在尝试创建带边框的网格,但使用此代码,只有第一个单元格有边框:
<Grid Margin="24,96,24,288" d:LayoutOverrides="GridBox">
<Grid.RowDefinitions>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
</Grid.ColumnDefinitions>
<Border BorderBrush="#FFFFFF" BorderThickness="1"/>
</Grid>
如何为所有单元格创建实心边框?
I'm trying to create grid with borders but with this code, only the first cell has border:
<Grid Margin="24,96,24,288" d:LayoutOverrides="GridBox">
<Grid.RowDefinitions>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
<RowDefinition Height="0.150*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
<ColumnDefinition Width="0.150*"/>
</Grid.ColumnDefinitions>
<Border BorderBrush="#FFFFFF" BorderThickness="1"/>
</Grid>
How do I create solid border for all the cells?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将网格包裹在边框中 :
您所做的方式是将边框元素添加到 Grid-Control 中 - 所以当然第一个单元格(如果您不设置 Grid.Row/Grid.Column 两者都会默认为 0)是用一个绘制的;)
如果您想为每个单元格创建边框,那么您必须将每个内容包装到一个 Border 元素中,或者您必须编辑网格的模板。
作为另一种选择,您可以尝试设置网格样式(这是一篇不错的文章< /a>)
这是该网站的另一个问题,涉及类似的事情: Styling a WPF 布局网格背景
为了使这一点更清晰,最简单(如果不是最精致的)为每个单元格获取(偶数)边框的方法是为每个单元格和网格自己设置边框(在标记或代码中) - 这是一个简化的示例:
Wrap the Grid into a Border :
The way you did was adding a Border-element into the Grid-Control - so of course the first cell (if you don't set Grid.Row/Grid.Column both will default to 0) was drawn with one ;)
If you want to create a border for each cell then you have to wrap each content into a Border-element or you have to edit the template for the grid.
As another alternative you could try to style the Grid (here is a nice article)
Here is another question from this site concerning a similar thing: Styling a WPF layout grid background
To make this a bit clearer the easiest (if not most refined) way to get a (even) border for each cell is to really set the boarder for each cell AND for the grid yourself (either in markup or code) - here is a simplified example: