This is a migrated thread and some comments may be shown as answers.

How to modify Hyperlinks

1 Answer 139 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
F
Top achievements
Rank 1
F asked on 24 Nov 2014, 07:31 PM
Hi. I'm trying to figure out how to locate modify the attributes of a Hyperlink (e.g. NavigateUri) after it's been created. What's puzzling me is that it seems that you can create a HyperlinkInfo object and then insert it into the document, but there doesn't seem to be any way to get a HyperlinkInfo object back from the document. When I import my document from RTF and then save as xaml, I got the following results (at bottom.)

I know that there are ways to pull back start tags, inlines, and so forth, but none of those seem to correspond to an actual HyperlinkInfo object. Furthermore, I'm seeing two different kinds of Hyperlink information (one in the <FieldRangeStart...>xxxx</FieldRangeStart...> pair, and another in the <HyperlinkRangeStart...>xxxx</HyperlinkRangeStart> pair. It's not clear where I should make mods.

Also: In your InsertHyperlink demo, if I insert a Hyperlink and then come back to edit it, then in module InsertHyperlinkDialog.xaml.cs, the ShowDialog procedure on line 74 includes a parameter for "CurrentHyperLinkInfo as HyperlinkInfo". Indeed, if I break at that point, the information is there, having apparently been supplied by the editor. However, I cannot figure out how to get the same info independent of the editor.

Please explain how this all works. The xaml snippet I promised is as follows:

<t:FieldRangeStart AnnotationID="558">
       <t:HyperlinkField DateTimeFormatting="" DisplayMode="Result" GeneralFormatting="" LocationInFile="" NavigateUri="hypercase:///cite_000031"
NumericFormatting="" Target="" />
</t:FieldRangeStart>
<t:HyperlinkRangeStart AnnotationID="559">
    <t:HyperlinkInfo NavigateUri="hypercase:///cite_000031" />
</t:HyperlinkRangeStart>
    <t:Span FontSize="16" FontStyle="Italic" StyleName="Hyperlink" Text="Ass’n of Am. Physicians and Surgeons Inc. v. Clinton" />
    <t:Span FontSize="16" StyleName="Hyperlink" Text=", 997 F.2d 898, 909 (D.C. Cir. 1993)" />
<t:HyperlinkRangeEnd AnnotationID="559" />
<t:FieldRangeEnd AnnotationID="558" />



 

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 27 Nov 2014, 03:51 PM
Hi,

Usually inserting a hyperlink in RadRichTextBox creates it as a HyperlinkRangeStart – HyperlinkRangeEnd pairs. You can see the example below to figure out how to get the HyperlinkInfo of the clicked hyperlink in this case: 
var clickedLink = this.radRichTextBox.Document
    .GetContainingAnnotationRanges<HyperlinkRangeStart>
                        (this.radRichTextBox
                        .Document
                        .CaretPosition
                        .GetCurrentInline())
    .First();
 
string uri = clickedLink.HyperlinkInfo.NavigateUri;
clickedLink.HyperlinkInfo.NavigateUri = "SomeURI";

Occasionally, importing a document would produce a HyperlinkField, which is an object corresponding to hyperlink fields in the Office OpenXml specification. In those cases you can follow the next snippet:
var start = this.radRichTextBox.Document
    .EnumerateChildrenOfType<FieldRangeStart>()
    .Where(x => x.Field is HyperlinkField)
    .FirstOrDefault();
 
if (start != null)
{
    (start.Field as HyperlinkField).NavigateUri = "SomeURI";
}

On a side note, the XAML you are getting as a result is very strange and we haven’t encountered such setup before. If you want you can send us the RTF file you are importing, so we can inspect it in details.

Regards,
Tanya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextBox
Asked by
F
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or