2

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

<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 样式而不是 Hyperlink 样式...

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

1 回答 1

3

从您的样式中删除x:Key并将其放入,DataGrid.Resources然后它以 this 中的所有Hyperlink控件为目标DataGrid

于 2012-05-24T15:18:46.023 回答