What is an easy way to set the background color for CustomGrid?

I have:

<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 background of a TextBox cell (where Background = "Yellow"). Setting the background for the TextBox does not help, because I need to set the background color for the entire cell, even if the text is missing.

How can I do that?

+8
background wpf xaml
source share
4 answers

You can place any panel in the panel and set its background color. For example:

 <Rectangle Fill="Black" IsHitTestVisible="False" Grid.Column="1" Grid.Row="1"/> 
+11
source share

Alternatively, place the border in the cell, then any control required within the border sets the background color property on the border.

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

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

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

If you indicate your cell by row + insert column. Then you can paste the text field wherever you want.

+3
source share

The WPF grid does not know what a cell is. Place the panel there and set its color.

+2
source share

All Articles