public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { DirectMessage directMessage = value as DirectMessage; if (directMessage != null) { TextBlock tb = new TextBlock(); TweetsTemplate tweetTemplate = new TweetsTemplate(); Hyperlink hyperLinkUser = new Hyperlink(); Style usernameStyle = (Style)tweetTemplate.FindResource("UsernameLinkStyle"); hyperLinkUser.Style = usernameStyle; hyperLinkUser.Command = TOBCommands.ShowUserProfile; hyperLinkUser.CommandParameter = directMessage; Binding bind = new Binding(); bind.Source = directMessage; hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind); TextBlock tbUserName = new TextBlock(); tbUserName.Text = directMessage.UserProfile.ScreenName; hyperLinkUser.Inlines.Add(tbUserName); tb.Inlines.Add(hyperLinkUser); tb.Inlines.Add(new Run(" ")); string dmContent = directMessage.Text; string[] statusParts = dmContent.Split(' '); Style linkStyle = (Style)tweetTemplate.FindResource("LinkStyle"); foreach (String part in statusParts) { Run magicRun = new Run(); if (part.StartsWith("http")) { Hyperlink link = new Hyperlink(); link.Style = linkStyle; link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate); TextBlock tblink = new TextBlock(); tblink.Text = part + " "; link.NavigateUri = new Uri(part); link.Inlines.Add(tblink); tb.Inlines.Add(link); magicRun = new Run(); } else { magicRun.Text = part + " "; tb.Inlines.Add(magicRun); } } return tb.Inlines; } else { return null; } }
private InlineCollection GetConvertedText(object value) { if (value == null) { return null; } TextBlock tb = new TextBlock(); TextBlock tbUserName = new TextBlock(); string statusContent = string.Empty; Binding bind = new Binding(); TweetsTemplate tweetTemplate = new TweetsTemplate(); Hyperlink hyperLinkUser = new Hyperlink(); Style usernameStyle = (Style)tweetTemplate.FindResource("UsernameLinkStyle"); hyperLinkUser.Style = usernameStyle; hyperLinkUser.Command = TOBCommands.ShowUserProfile; switch (value.GetType().Name) { case "Status": { statusContent = StatusText(value, tb, tbUserName, statusContent, bind, hyperLinkUser); break; } case "TwitterSearchStatus": { statusContent = SearchText(value, tb, tbUserName, statusContent, bind, hyperLinkUser); break; } case "TwitterStatus": { statusContent = TwitterStatusText(value, tb, tbUserName, statusContent, bind, hyperLinkUser); break; } } return GetInlineCollections(tb, statusContent, bind, tweetTemplate, hyperLinkUser); }
private InlineCollection GetConvertedText(object value) { if (value == null) { return null; } TextBlock tb = new TextBlock(); TextBlock tbUserName = new TextBlock(); string statusContent = string.Empty; Binding bind = new Binding(); TweetsTemplate tweetTemplate = new TweetsTemplate(); Style usernameStyle = (Style)tweetTemplate.FindResource("UsernameLinkStyle"); statusContent = StatusText(value, tb, tbUserName, statusContent); return GetInlineCollections(tb, statusContent, bind, tweetTemplate); }
private InlineCollection GetInlineCollections(TextBlock tb, string statusContent, Binding bind, TweetsTemplate tweetTemplate) { string[] statusParts = statusContent.Split(' '); Style linkStyle = (Style)tweetTemplate.FindResource("LinkStyle"); string parsedStr = ""; foreach (String part in statusParts) { parsedStr = part.TrimStart(_delimChars); //Check for links if (parsedStr.StartsWith("http")) { Hyperlink link = new Hyperlink(); link.Style = linkStyle; Run run = new Run(part + " "); try { link.NavigateUri = new Uri(parsedStr); link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate); } catch (Exception e) { TOB.Logger.TOBLogger.WriteDebugInfo(e.ToString()); } link.Inlines.Add(run); tb.Inlines.Add(link); } //Check for user tags else if (parsedStr.StartsWith("@")) { Hyperlink hplink = new Hyperlink(); hplink.Style = linkStyle; hplink.Command = TOBCommands.ShowUserProfileForTags; hplink.CommandParameter = parsedStr.TrimEnd(_delimChars); Run run = new Run(part + " "); hplink.Inlines.Add(run); tb.Inlines.Add(hplink); } //check for #tags. else if (parsedStr.StartsWith("#")) { Hyperlink hplinks = new Hyperlink(); hplinks.Style = linkStyle; hplinks.Command = TOBCommands.ShowFilterForTags; hplinks.CommandParameter = parsedStr.TrimEnd(_delimChars); Run run = new Run(part + " "); hplinks.Inlines.Add(run); tb.Inlines.Add(hplinks); } else { Run magicRun = new Run(); magicRun.Text = part + " "; tb.Inlines.Add(magicRun); } } return tb.Inlines; }