我们可以更改WPF超链接中使用的颜色吗? [英] Can we change the colors used in WPF Hyperlink?

查看:187
本文介绍了我们可以更改WPF超链接中使用的颜色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我们可以更改WPF超链接中使用的颜色,如普通颜色,悬停颜色,单击颜色吗?

我检查了属性但没有用.


城堡骑士
在茂密的丛林中
今晚狮子沉睡...

Hi All,
Can we change the colors used in WPF Hyperlink like normal, hover, clicked colors?

I checked the properties but no use.


Castle Rider
In the jungle the mighty jungle
The lion sleeps tonight...

推荐答案

您可以更改常规通过重新设置超链接的样式来设置,悬停和禁用颜色:

You can change the normal, hover, and disabled colors by restyling Hyperlink:

<Style x:Key="{x:Type Hyperlink}" TargetType="{x:Type Hyperlink}">
    <Setter Property="Foreground" Value="Blue"/>
    <Setter Property="TextDecorations" Value="Underline"/>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
             <Setter Property="Foreground" Value="Red"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
             <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="True">
            <Setter Property="Cursor" Value="Hand"/>
        </Trigger>
    </Style.Triggers>
</Style>

如果需要其他单击的颜色,则可能需要对Hyperlink进行子类化,添加一个指示是否已单击超链接的属性,然后向该样式添加另一个触发器.

If you need a different clicked color, you probably need to subclass Hyperlink, add a property indicating whether the hyperlink has been clicked, and add another trigger to the style.


这篇关于我们可以更改WPF超链接中使用的颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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