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上設置樣式。 –