[英]How to change row/column background color in Grid?
我嘗試使用一些行定義屬性,但這對我沒有幫助。 我也嘗試使用Grid.Rows[0].BackColor = Color.Red;
但它也不起作用。
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
Grid
沒有提供一種簡單的方法來為其“單元格”着色。
有多種方法可以為它們着色,最簡單的方法就是簡單地使用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>
如何使用循環/周期更改每個單元格? 回復!
<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>
您可以使用。
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.