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

标签 wpf grid background-color

我有一个 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/

相关文章:

c# - WPF 网格上的底部边框

c# - 如何绑定(bind)到控件的文字实际宽度(包括其边距)?

extjs - Ext JS 获取网格的选定行

java - Firefox 无法在 VM 机器中启动

ios - 更新 UITableView 部分标题的背景颜色

wpf - 在 3D 对象 wpf 中放置一个控件

c# - 如何右对齐 WPF ListItem 的某些元素?

twitter-bootstrap-3 - 在 Bootstrap 的列宽中使用小数

java - 如何在 jtextfield 上设置半透明背景颜色?

java - 更改 JButtons 背景的最佳方法