WPF-style hyperlinks in DataGrids

I need to create hyperlinks in a WPF4 DataGrid control (they appear in columns of type DataGridHyperlinkColumn). I have many DataGrids in the project and would like to apply a hyperlink style for all of them.

I found this Q & A: WPF Style DataGridHyperlinkColumn and created a style for managing HyperLink:

<Style TargetType="{x:Type Hyperlink}"> <Setter Property="TextDecorations" Value="" /> </Style> 

It works great, but obviously it also affects all other hyperlinks, for example. in

 <TextBlock> <Hyperlink NavigateUri="http://www.google.co.in">Click here</Hyperlink> </TextBlock> 

How do I target only hyperlinks in DataGrids? In CSS syntax, it will be something like

 DataGrid Hyperlink {TextDecorations: ""; } 
+4
source share
1 answer

Due to the inheritance of the property value, all reference instances inherit the style you created because you did not use the x: key attribute.

You can add the x: Key attribute :

 <Style TargetType="{x:Type Hyperlink}" x:Key="HyperlinkStyle1"> <Setter Property="TextDecorations" Value="" /> </Style> 

using this, you can reference it from your controls, as shown below:

 <Hyperlink NavigateUri="http://www.google.co.in" Style={StaticResource HyperlinkStyle1}>Click here</Hyperlink> 
+3
source

Source: https://habr.com/ru/post/1414734/


All Articles