2012-05-24 65 views
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}" /> 

回答

3

从您的风格x:Key并把它放在DataGrid.Resources则目标之内这一切Hyperlink控制DataGrid

+0

如果我需要在多个项目中使用此风格,那么该怎么办? –

+0

然后将样式放在ResourceDictionary中,就像您想要重用的任何其他样式一样。 – LPL

+2

然后它适用于所有超链接。 令人讨厌的是你不能直接在DataGridHyperLinkColumn上设置样式。 –