9

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?

4 Answers 4

13

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"/>
6

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>
6

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.