I have created a datagrid in WPF...
I have defined several custom Columns..
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding HeadC}" />
<TextBlock Text="{Binding HeadCPercent}" Foreground="#FFF05D1D" />
</StackPanel>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
The problem is that when a row is slected the seconds textblock color doesnt change and it is hardly visible...
Any solution to this problem ?
Add DataTrigger
to the DataTemplate
triggers collection that would change foreground based on selected state of the row. Like in the following example:
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding HeadC}" />
<TextBlock x:Name="tbPercent" Text="{Binding HeadCPercent}" Foreground="#FFF05D1D"/>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGridRow}}}" Value="True">
<Setter Property="Foreground" TargetName="tbPercent" Value="Blue" />
</DataTrigger>
</DataTemlate.Triggers>
</DataTemplate>
I took this answer as a basis and adjusted it to your question. I could made a typo in the code but you should get the idea :). Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With