简体   繁体   English

Windows Phone中的RichTextBox超链接颜色

[英]RichTextBox Hyperlink color in Windows Phone

I have an application that displays some text in a RichTextBox; 我有一个在RichTextBox中显示一些文本的应用程序; I have some links in the text, so use Hyperlinks to display them. 我的文字中有一些链接,因此请使用Hyperlinks显示它们。

My problem is that I can't get to set a color to the Hyperlink Foreground property. 我的问题是我无法为“ Hyperlink Foreground属性设置颜色。 I know it can't pass it via RichTextBox.Xaml property; 我知道它无法通过RichTextBox.Xaml属性传递它; moreover, If i do 此外,如果我愿意

<RichTextBox.Resources>
    <Style TargetType="Hyperlink" x:Key="HyperlinkColor">
        <Setter Property="Foreground" Value="Black"/>
    </Style>
</RichTextBox.Resources>

nothing happens: the hyperlink remains stuck with the default color. 没有任何反应:超链接仍然停留在默认颜色下。

Is there a way to get the color I want on Hyperlinks in my RichTextBox? 有没有办法在RichTextBox的超链接上获得我想要的颜色?

You can do: 你可以做:

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

OR 要么

cs: CS:

        string xaml =
            @"<Section xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
                <Paragraph>
                    <Hyperlink Foreground=""Green"">Hyperlink</Hyperlink>
                </Paragraph>
            </Section>";

        RichTextBox.Xaml = xaml;

I hope this helps :) 我希望这有帮助 :)

I just set the foreground property like this: 我只是这样设置前台属性:

<Hyperlink NavigateUri="http://www.****.org" TargetName="_blank" Foreground="#FF337CBB">www.***.org</Hyperlink>

and it worked out for me. 它为我解决了。

Remove the x:Key attribute from Style, so that it gets applied automatically to all hyperlinks which exists under RichTextBox. 从样式中删除x:Key属性,以便它自动应用于RichTextBox下存在的所有超链接。

<Style TargetType="Hyperlink">
   <Setter Property="Foreground" Value="Black"/>
</Style>

I've faced the same problem! 我也遇到过同样的问题! And here's the solution that works: 这是可行的解决方案:

<SolidColorBrush x:Key="HyperlinkForegroundThemeBrush"
                             Color="TheColorYouNeed" />
<SolidColorBrush x:Key="HyperlinkPressedForegroundThemeBrush"
                             Color="TheColorYouNeed"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM