Reputation: 667
I spent some time on the questions: how to convert a selection in a RichEditBox into a hyperlink and how to remove this link again.
Upvotes: 0
Views: 630
Reputation: 667
The solution is simple. But there are some workarounds to consider:
public void InsertLink(RichEditBox control, string url)
{
//Check some conditions - else property assignment crashes
if (string.IsNullOrEmpty(url)) return;
if (string.IsNullOrEmpty(control.Document.Selection.Text)) return;
control.Document.Selection.Link = "\"" + url + "\"";
}
public void RemoveLink(RichEditBox control)
{
//Can only set Link to empty string, if a link is assigned,
//else property assignment crashes
if (string.IsNullOrEmpty(control.Document.Selection.Link)) return;
control.Document.Selection.Link = "";
}
Upvotes: 1