You can use the Hyperlink class. This is a FrameworkContentElement, so you can use it in a TextBlock or FlowDocument, or anywhere else where you can embed content.
<TextBlock> <Run>Text</Run> <Hyperlink NavigateUri="http://stackoverflow.com">with</Hyperlink> <Run>some</Run> <Hyperlink NavigateUri="http://google.com">hyperlinks</Hyperlink> </TextBlock>
You may want to use RichTextBox as part of your editor. It will host a FlowDocument, which may contain materials such as hyperlinks.
Update. There are two ways to handle clicks on a hyperlink. One of them is to handle the RequestNavigate event. This is a routable event , so you can either attach the handler to the hyperlink itself, or attach it to the element above in the tree, for example, Window or RichTextBox:
// On a specific Hyperlink myLink.RequestNavigate += new RequestNavigateEventHandler(RequestNavigateHandler); // To handle all Hyperlinks in the RichTextBox richTextBox1.AddHandler(Hyperlink.RequestNavigateEvent, new RequestNavigateEventHandler(RequestNavigateHandler));
Another way is to use commanding by setting Command in a hyperlink to ICommand . The Executed method on ICommand will be called when a hyperlink is clicked.
If you want to launch the browser in the handler, you can pass the URI to Process.Start :
private void RequestNavigateHandler(object sender, RequestNavigateEventArgs e) { Process.Start(e.Uri.ToString()); }
source share