在WP7中设置网格边框

发布于 2024-12-06 06:56:04 字数 943 浏览 0 评论 0原文

我正在尝试创建带边框的网格,但使用此代码,只有第一个单元格有边框:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡绿茶香 2024-12-13 06:56:04

将网格包裹在边框中

<Border  BorderBrush="#FF0000" BorderThickness="5" Margin="24,96,24,288">
    <Grid>
       ....
    </Grid>
</Border>

您所做的方式是将边框元素添加到 Grid-Control 中 - 所以当然第一个单元格(如果您不设置 Grid.Row/Grid.Column 两者都会默认为 0)是用一个绘制的;)

如果您想为每个单元格创建边框,那么您必须将每个内容包装到一个 Border 元素中,或者您必须编辑网格的模板。
作为另一种选择,您可以尝试设置网格样式(这是一篇不错的文章< /a>)
这是该网站的另一个问题,涉及类似的事情:
Styling a WPF 布局网格背景

为了使这一点更清晰,最简单(如果不是最精致的)为每个单元格获取(偶数)边框的方法是为每个单元格和网格自己设置边框(在标记或代码中) - 这是一个简化的示例:

<Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="0" Grid.Column="0" Margin="24,96,24,288" >
    <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="0" Grid.Column="0"/>
            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="0" Grid.Column="1"/>
            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="1" Grid.Column="0"/>
            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="1" Grid.Column="1"/>
    </Grid>
</Border>

Wrap the Grid into a Border :

<Border  BorderBrush="#FF0000" BorderThickness="5" Margin="24,96,24,288">
    <Grid>
       ....
    </Grid>
</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:

<Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="0" Grid.Column="0" Margin="24,96,24,288" >
    <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="0" Grid.Column="0"/>
            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="0" Grid.Column="1"/>
            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="1" Grid.Column="0"/>
            <Border BorderBrush="#FF0000" BorderThickness="2" Grid.Row="1" Grid.Column="1"/>
    </Grid>
</Border>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文