我有一个 wpf mvvm 应用程序。 并拥有一个包含多列的 GRID
在wpf中设置网格列背景色的最佳方法是什么?
最佳答案
dabble125 的答案很完美,但为了给您提供一个示例并提及注意矩形的放置位置很重要,请参阅代码:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!-- this is not a good place for text block.
the text block is beneath the rectangle
so it would not be seen -->
<!--<TextBlock Grid.Column="1" Text="Some Text"/>-->
<Rectangle Grid.Column="1" Grid.RowSpan="1000">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF83FF97" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Column="1" Text="Some Text"/>
</Grid>
关于wpf - 如何在wpf中设置网格列的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6347195/