Datagrid Column Text Background Colour in WPF

Posted by Issac under WPF on 2/22/2012 | Points: 10 | Views : 5638 | Status : [Member] | Replies : 2
Hi,
im having a grid and in that there are 3columns
for one column im highlighting the text background color and im success for that
with the following code

<DataGridTextColumn Header="" Binding="{Binding ServiceType.Name}" Width="75">
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextBlock.Background" Value="Gray" />
<Setter Property="TextBlock.FontSize" Value="12" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

now when in click any row in DataGrid i would like to change the color from 'Gray' to 'White'
i.e <Setter Property="TextBlock.Background" Value="Gray" /> to <Setter Property="TextBlock.Background" Value="White" />

can anyone help which trigger to be used here




Responses

Posted by: Blessyjees on: 2/22/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi,

try like this

<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="DataGridRow.IsSelected" Value="True">
<Setter Property="Background" Value="#CCDAFF" />
</Trigger>
</Style.Triggers>
</Style>

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Issac, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Issac on: 2/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi...tried with this...but it is not working....

Issac, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response