WPF Style DataGridHyperlinkColumn

試著忘記壹切 提交于 2019-12-12 20:23:07

问题


I created a style for a hyperlink control:

<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>

How can I use this style in a DataGridHyperlinkColumn?

The ElementStyle of this kind of column asks for a TextBlock style instead of an Hyperlink one...

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

回答1:


Remove the x:Key from your style and put it in DataGrid.Resources then it targets all Hyperlink controls within this DataGrid.



来源:https://stackoverflow.com/questions/10739766/wpf-style-datagridhyperlinkcolumn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!