I\'m trying to dynamically add some hyperlinks to a RichTextBox using WPF and C# but am not having much success. My code is summarised below:
FlowDocument do
A simple solution for reading a richTextBox
text and transforming it into a link:
richTextBox.IsDocumentEnabled = true;
TextPointer t1 = richTextBox1.Document.ContentStart;
TextPointer t2 = richTextBox1.Document.ContentEnd;
TextRange tr = TextRange(t1,t2);
string URI = tr.Text;
Hyperlink link = new Hyperlink(t1, t2);
link.IsEnabled = true;
link.NavigateUri = new Uri(URI);
link.RequestNavigate += new RequestNavigateEventHandler(link_RequestNavigate);
private void link_RequestNavigate(object sender,RequestNavigateEventArgs e)
{
System.Diagnostics.Process.Start(e.Uri.AbsoluteUri.ToString());
}
The Document
in a RichTextBox
is disabled by default, set RichtTextBox.IsDocumentEnabled
to true
.