private static void StatusTextPropertyChangedCallback(DependencyObject target, DependencyPropertyChangedEventArgs eventArgs) { var textBlock = (StatusTextBlock)target; textBlock.Inlines.Clear(); string newValue = eventArgs.NewValue as string; if (newValue != null) { textBlock.Inlines.AddRange(StatusTextBlock.GenerateInlinesFromRawEntryText(newValue)); } }
internal static IEnumerable <Inline> GenerateInlinesFromRawEntryText(string entryText) { int startIndex = 0; Match match = StatusTextBlock.s_uriMatchingRegex.Match(entryText); while (match.Success) { if (startIndex != match.Index) { yield return(new Run(StatusTextBlock.DecodeStatusEntryText(entryText.Substring(startIndex, match.Index - startIndex)))); } Hyperlink hyperLink = new Hyperlink(new Run(match.Value)); hyperLink.TextDecorations = null; hyperLink.MouseMove += new System.Windows.Input.MouseEventHandler(hyperLink_MouseMove); hyperLink.MouseLeave += new System.Windows.Input.MouseEventHandler(hyperLink_MouseLeave); string uri = match.Value; if (match.Groups["emailAddress"].Success) { uri = "mailto:" + uri; } else if (match.Groups["toTwitterScreenName"].Success) { uri = "http://twitter.com/" + uri.Substring(1); } hyperLink.NavigateUri = new Uri(uri); hyperLink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(hyperLink_RequestNavigate); yield return(hyperLink); startIndex = match.Index + match.Length; match = match.NextMatch(); } if (startIndex != entryText.Length) { yield return(new Run(StatusTextBlock.DecodeStatusEntryText(entryText.Substring(startIndex)))); } }