[英]How to change row/column background color in Grid?
I tried to use some atributes of rowdefinition, but it doesn't help me. 我尝试使用一些行定义属性,但这对我没有帮助。 I also tried to use Grid.Rows[0].BackColor = Color.Red;
我也尝试使用Grid.Rows[0].BackColor = Color.Red;
but it doesn't work too. 但它也不起作用。
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
The Grid
does not provide a simple way to color its "cells". Grid
没有提供一种简单的方法来为其“单元格”着色。
There are ways to color them, and the most easiest is to simply use a Border
: 有多种方法可以为它们着色,最简单的方法就是简单地使用Border
:
<Grid>
<!-- At the top so that they don't overlap anything else. -->
<Border Background="Red" Grid.Row="0" Grid.Column="0" />
<Border Background="Red" Grid.Row="0" Grid.Column="1" />
...
</Grid>
How can I change every cell using loop/cycle? 如何使用循环/周期更改每个单元格? reply !! 回复!
<Grid x:Name="gridMain">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Border Background="Red" Grid.Row="0" />
<Border Background="Blue" Grid.Row="1" />
</Grid>
you can use. 您可以使用。
foreach (Border item in gridMain.Children)
{
if (item.Background == Brushes.Blue)
item.Background = Brushes.Red;
else
item.Background = Brushes.Blue;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.