WPF样式DataGridHyperlinkColumn

时间:2012-05-24 14:42:34

标签: wpf wpfdatagrid wpf-4.0

我为超链接控件创建了一个样式:

<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>

如何在DataGridHyperlinkColumn中使用此样式?

此类列的ElementStyle要求使用TextBlock样式而不是超链接样式...

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

1 个答案:

答案 0 :(得分:3)

从您的样式中移除x:Key并将其放在DataGrid.Resources中,然后定位到此Hyperlink中的所有DataGrid控件。