What is a simple way to set the background cell color for a CustomGrid?

21,311

Solution 1

You can put some type of panel in that area and set its background color. For example:

<Rectangle Fill="Black" IsHitTestVisible="False" Grid.Column="1" Grid.Row="1"/>

Solution 2

Alternatively put a border in the cell, then whatever control required within the border setting the background colour property of the border.

<Border Grid.Column="0" Grid.Row="0" Background="#FF3C3C3F">
     <TextBlock>Some Text</TextBlock>
</Border>

Solution 3

To set the background color for an entire row or column, add this in the row or column definition:

<Grid Grid.Row="0" Grid.Column="0" Background="SomeColor"/>

Where you specify your cell by row + column insertion. Then you can insert your textbox wherever you want.

Solution 4

WPF grid doesn't know what a "cell" is. Put a panel in there and set its color.

Share:
21,311
cnd
Author by

cnd

Updated on July 09, 2022

Comments

  • cnd
    cnd almost 2 years

    I've got:

    <CustomControl:GridControl ShowCustomGridLines="True" Grid.Column="2" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
            <TextBlock Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Name="txbCaption" Text="{Binding Caption}" />
                <CustomControl:GridControl ShowCustomGridLines="True" Grid.Column="2" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Column="0" Grid.Row="1" Text="П" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    <TextBlock Grid.Column="1" Grid.Row="1" Text="Ф" HorizontalAlignment="Center" VerticalAlignment="Center" Background="Yellow" />
                    <TextBlock Grid.Column="2" Grid.Row="1" Text="%" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </CustomControl:GridControl>
    

    I want to set the cell background of a TextBox (where Background="Yellow"). Setting the background for a TextBox doesn't help because I need to set the background color for the whole cell, even if there is no text.

    How can this be done?