WPF样式DataGridHyperlinkColumn [英] WPF Style DataGridHyperlinkColumn

查看:257
本文介绍了WPF样式DataGridHyperlinkColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为超链接控件创建了一种样式:

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>

如何在DataGridHyperlinkColumn中使用这种样式?

How can I use this style in a DataGridHyperlinkColumn?

此类列的ElementStyle要求使用TextBlock样式而不是Hyperlink样式。

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}" />


推荐答案

删除 x:Key 从您的样式并将其放入 DataGrid.Resources ,然后将其定位到其中的所有 Hyperlink 控件此 DataGrid

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

这篇关于WPF样式DataGridHyperlinkColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆