Eduardo Brites
Eduardo Brites

Reputation: 4766

WPF Style DataGridHyperlinkColumn

I created a style for a hyperlink control:

<Style x:Key="MyHyperlink" TargetType="{x:Type Hyperlink}">
    <Setter Property="Foreground" Value="{StaticResource HyperlinkBrush}" />
    <Setter Property="IsEnabled" Value="{Binding IsEnabled,RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}}" />
    <Style.Triggers>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Cursor" Value="Hand"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="True" >
            <Setter Property="Foreground" Value="{StaticResource HyperlinkMouseOverBrush}"  />
        </Trigger>
    </Style.Triggers>
</Style>

How can I use this style in a DataGridHyperlinkColumn?

The ElementStyle of this kind of column asks for a TextBlock style instead of an Hyperlink one...

<DataGridHyperlinkColumn EditingElementStyle="{StaticResource MyDataGridTextColumn}" ElementStyle="{StaticResource MyDataGridHyperlinkColumn}"
                            Header="WebSite" Binding="{Binding Site, NotifyOnValidationError=True,ValidatesOnDataErrors=True}" />

Upvotes: 2

Views: 2237

Answers (1)

LPL
LPL

Reputation: 17063

Remove the x:Key from your style and put it in DataGrid.Resources then it targets all Hyperlink controls within this DataGrid.

Upvotes: 3

Related Questions