将背景颜色更改为网格中的行 [英] Change background color to rows in grid

查看:73
本文介绍了将背景颜色更改为网格中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我想更改网格中每隔一行的背景颜色.即第一行是白色,第二行是蓝色,第三行是白色,第四行是蓝色,依此类推.可能吗?我该怎么做?提前谢谢. 

Hi everyone. I want to change the background color of every other row in a grid. i.e. First row is white, second blue, third white, fourth blue and so on. Is it possible? How do I do it? Thanks in advance. 

推荐答案

您可以添加横跨整行的Grid或Border元素,并用颜色填充它们.如果将网格内容放在最前面,它们将作为行背景.

You can add Grid or Border elements that span the entire row, and fill them with colors. They will function as row backgrounds if put your grid contents in front.

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="60"/>
            <RowDefinition Height="60"/>
            <RowDefinition Height="60"/>
            <RowDefinition Height="60"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition Width="100"/>
        </Grid.ColumnDefinitions>
        <Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4" Background="Red"/>
        <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Background="Green"/>
        <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Background="Blue"/>
        <Grid Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Background="Gray"/>

        <TextBlock Grid.Row="2" Grid.Column="1" Text="text"/>
    </Grid>


这篇关于将背景颜色更改为网格中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆