![](/img/trans.png)
[英]How to replace link to hyperlink in RichTextBox (Windows phone)
[英]RichTextBox Hyperlink color in Windows Phone
我有一个在RichTextBox中显示一些文本的应用程序; 我的文字中有一些链接,因此请使用Hyperlinks
显示它们。
我的问题是我无法为“ Hyperlink
Foreground
属性设置颜色。 我知道它无法通过RichTextBox.Xaml
属性传递它; 此外,如果我愿意
<RichTextBox.Resources>
<Style TargetType="Hyperlink" x:Key="HyperlinkColor">
<Setter Property="Foreground" Value="Black"/>
</Style>
</RichTextBox.Resources>
没有任何反应:超链接仍然停留在默认颜色下。
有没有办法在RichTextBox的超链接上获得我想要的颜色?
你可以做:
<RichTextBox>
<RichTextBox.Resources>
<SolidColorBrush x:Key="HyperlinkColorBrush"
Color="White" />
</RichTextBox.Resources>
<Paragraph>
<Hyperlink Foreground="{StaticResource HyperlinkColorBrush}">
Hi!
</Hyperlink>
</Paragraph>
<Paragraph>
<Hyperlink Foreground="{StaticResource HyperlinkColorBrush}">
How are you?
</Hyperlink>
</Paragraph>
</RichTextBox>
要么
CS:
string xaml =
@"<Section xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<Paragraph>
<Hyperlink Foreground=""Green"">Hyperlink</Hyperlink>
</Paragraph>
</Section>";
RichTextBox.Xaml = xaml;
我希望这有帮助 :)
我只是这样设置前台属性:
<Hyperlink NavigateUri="http://www.****.org" TargetName="_blank" Foreground="#FF337CBB">www.***.org</Hyperlink>
它为我解决了。
从样式中删除x:Key
属性,以便它自动应用于RichTextBox下存在的所有超链接。
<Style TargetType="Hyperlink">
<Setter Property="Foreground" Value="Black"/>
</Style>
我也遇到过同样的问题! 这是可行的解决方案:
<SolidColorBrush x:Key="HyperlinkForegroundThemeBrush"
Color="TheColorYouNeed" />
<SolidColorBrush x:Key="HyperlinkPressedForegroundThemeBrush"
Color="TheColorYouNeed"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.