由于Hyperlink保存时标签不会丢失,另一种方法是扫描加载的文档以查找这些标签并重新应用它的属性——点击事件和导航 uri。
void restoreHyperlinks()
{
    TextRange tr = new TextRange(_richTextBox.Document.ContentStart, _richTextBox.Document.ContentEnd);
    TextPointer tp = tr.Start;
    bool bFound = false;
    foreach (System.Text.RegularExpressions.Match match in UrlRegex.Matches(tr.Text))
    {
        if (tp == null)
            tp = tr.Start;
        bFound = false;
        while (tp != null && !bFound)
        {
            if (tp.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
            {
                string textRun = tp.GetTextInRun(LogicalDirection.Forward);
                int indexInRun = textRun.IndexOf(match.Value);
                if (indexInRun > -1)
                {
                    bFound = true;
                    Inline parent = tp.Parent as Inline;
                    while (parent != null && !(parent is Hyperlink))
                    {
                        parent = parent.Parent as Inline;
                    }
                    if (parent is Hyperlink)
                    {
                        Hyperlink hyperlink = (Hyperlink)parent;
                        if (isHyperlink(match.Value))
                        {
                            Uri uri = new Uri(match.Value, UriKind.RelativeOrAbsolute);
                            if (!uri.IsAbsoluteUri)
                            {
                                uri = new Uri(@"http://" + match.Value, UriKind.Absolute);
                            }
                            if (uri != null)
                            {
                                hyperlink.NavigateUri = uri;
                                hyperlink.Click += Hyperlink_Click;
                            }
                        }
                    }
               }
            }
            tp = tp.GetNextContextPosition(LogicalDirection.Forward);
        }
    }
}
正则表达式是:
private static readonly System.Text.RegularExpressions.Regex UrlRegex = new System.Text.RegularExpressions.Regex(@"(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~/|/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?");
isHyperlink是另一种检查 URL 的方法 - 代码取自:
 http: //marcangers.com/detect-urls-add-hyperlinks-wpf-richtextbox-automatically/
希望这可以帮助!干杯,斯蒂芬