如何在WPF中设置网格列的背景颜色?

| 我有一个wpf mvvm应用程序。 并具有多个列的GRID 在wpf中设置网格列的背景色的最佳方法是什么?     
已邀请:
        单程: 创建一个矩形并将其填充设置为您选择的颜色。 然后将其Grid.RowSpan值设置为大量或您拥有的行数。     
        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>
    

要回复问题请先登录注册