I need to style hyperlinks in WPF4 DataGrid control (they appear in columns of type DataGridHyperlinkColumn). I have many DataGrids in the project and would like to apply the hyperlink style to all of them.
I found this Q&A: WPF Style DataGridHyperlinkColumn and created the style for HyperLink control:
<Style TargetType="{x:Type Hyperlink}">
<Setter Property="TextDecorations" Value="" />
</Style>
It works fine, but obviously it also affects all other hyperlinks, eg. in
<TextBlock>
<Hyperlink NavigateUri="http://www.google.co.in">Click here</Hyperlink>
</TextBlock>
How can I target only hyperlinks in DataGrids? In CSS syntax it would be something like
DataGrid Hyperlink {TextDecorations: ""; }
Due to property value inheritance all instances of links inherits the style that you have created because you did not use x:key attribute.
You can add x:Key attribute:
by using this you can reference this from your controls like below: