One of the columns in my DataGrid
contains a Hyperlink
in a TextBlock
. When a row is selected, the hyperlink shows as blue on blue, so i want to change it's text color to white. How can I do that?
The DataGrid
looks like this:
<DataGrid>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Title">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap">
<Hyperlink NavigateUri="{Binding Url}">
<Run Text="{Binding Title}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I've tried
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="TextBlock.Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
and the same code with TextElement
instead of TextBlock
. Both work for other columns, but not for this one with hyperlink.
Use the following declaration for the link:
<Run Text="{Binding Title}"
Foreground="{Binding
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridCell},
Path=Foreground}"/>
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