更改超链接的悬停颜色 [英] Changing Hover color of Hyperlink
问题描述
目前正在努力理解如何正确设置 Windows.UI.Xaml.Documents.Hyperlink
文本元素的样式...问题很简单:更改正常"前景色效果很好,但是一旦超链接悬停,它就会更改其颜色(这很容易解释)
Currently struggeling understanding how to style the Windows.UI.Xaml.Documents.Hyperlink
textelement proper ...
The problem is simple: Changing the "normal" foreground color works fine but as soon as the hyperlink gets hovered it changes its color (which is simple to explain)
我遇到的问题是:如何更改超链接文本元素的其他视觉状态的前景(黑底黑字看起来很糟糕……:))?
The question i struggle with is: how to change the foreground of other visual states of a hyperlink textelement (black on black looks very bad ... :) )?
Hyperlink lnk = new Hyperlink();
lnk.Inlines.Add(new Run { Text = linkText });
lnk.Foreground = Application.Current.Resources["pr0_orange"] as SolidColorBrush;
问候X39
推荐答案
根据 超链接和主题/样式行为来自 HyperLink 类文章、
超链接不继承自 Control,因此它没有 Style 属性或模板.您可以编辑从 TextElement 继承的属性,例如 Foreground 或 FontFamily,以更改超链接的外观,但不能使用通用样式或模板来应用更改.不要使用模板,而应考虑使用通用资源作为超链接属性的值以提供一致性.超链接的某些属性使用系统提供的 {ThemeResource} 标记扩展值的默认值.当用户在运行时更改系统主题时,这使得超链接外观能够以适当的方式切换.
Hyperlink doesn't inherit from Control, so it doesn't have a Style property or a Template. You can edit the properties that are inherited from TextElement, such as Foreground or FontFamily, to change the appearance of a Hyperlink, but you can't use a common style or template to apply changes. Instead of using a template, consider using common resources for values of Hyperlink properties to provide consistency. Some properties of Hyperlink use defaults from a {ThemeResource} markup extension value provided by the system. This enables the Hyperlink appearance to switch in appropriate ways when the user changes the system theme at run-time.
您无法更改样式或模板中的悬停前景色.唯一的方法是更改系统ThemeResource 的SystemControlHyperlinkBaseMediumBrush
属性值.但我强烈建议你不要这样做,因为它会改变所有相关的样式.
You cannot change the hover foreground color in a style or template. The only way is to change the SystemControlHyperlinkBaseMediumBrush
property value of system ThemeResource. But I strongly recommend you not to do this because it will change all the relative styles.
您可以使用 HyperlinkButton,您可以只需设置 PointerOver
VisualState 即可更改悬停颜色.如果 HyperlinkButton 不能很好地满足您的要求,建议您自定义一个控件.
You can use HyperlinkButton, which you can change the hover color by simply set the PointerOver
VisualState.
If HyperlinkButton cannot meet your requirements well, recommend you to custom a control.
这篇关于更改超链接的悬停颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!