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

Rel*_*ity 6 wpf grid background-color

我有一个wpf mvvm应用程序.并且具有多列的GRID

什么是在wpf中设置网格列的背景颜色的最佳方法?

Ehs*_*adi 16

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>
Run Code Online (Sandbox Code Playgroud)


小智 6

单程:

创建一个矩形并将其填充设置为您选择的颜色.
然后将其Grid.RowSpan值设置为您拥有的大数字或行数.