2
我创建了一个超链接控件的样式:WPF风格DataGridHyperlinkColumn
<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}" />
如果我需要在多个项目中使用此风格,那么该怎么办? –
然后将样式放在ResourceDictionary中,就像您想要重用的任何其他样式一样。 – LPL
然后它适用于所有超链接。 令人讨厌的是你不能直接在DataGridHyperLinkColumn上设置样式。 –