WPF样式的DataGridHyperlinkColumn
我为超链接控件创建了一个样式:WPF样式的DataGridHyperlinkColumn,wpf,wpfdatagrid,wpf-4.0,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={Relativ
<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要求使用文本块样式,而不是超链接样式
<DataGridHyperlinkColumn EditingElementStyle="{StaticResource MyDataGridTextColumn}" ElementStyle="{StaticResource MyDataGridHyperlinkColumn}"
Header="WebSite" Binding="{Binding Site, NotifyOnValidationError=True,ValidatesOnDataErrors=True}" />
从样式中删除x:Key
并将其放入DataGrid.Resources
中,然后它将指向此DataGrid
中的所有Hyperlink
控件。如果我需要在多个项目中使用此样式,该如何处理?然后将样式放入ResourceDictionary中,就像您希望使用的任何其他样式一样重用。然后它适用于所有超链接。无法直接在DataGridHyperLinkColumn上设置样式很烦人。