protected override void Render() { InlineCollection inlines = Inlines; inlines.Clear(); TwitterStatusViewer v = Owner; if (v == null) { return; } Status s = v.DataContext as Status; if (s == null) { return; } Status s1 = s; if (s.RetweetedStatus != null) { s = s.RetweetedStatus; } v.CreateTweetBody(s.Text, inlines); }
protected override void Render () { InlineCollection inlines = Inlines; while (inlines.Count > 1) inlines.Remove (inlines.LastInline); TwitterStatusViewer v = Owner; if (v == null) return; Status s = v.DataContext as Status; if (s == null) return; Status s1 = s; if (s.RetweetedStatus != null) s = s.RetweetedStatus; // 改行や連続する空白を削除 string text = s.Text; StringBuilder sb = new StringBuilder (text.Length); int state = 0; for (int i = 0; i < text.Length; i ++) { char c = text[i]; if (c == '\r' || c == '\n') continue; if (char.IsWhiteSpace (c)) { if (state == 1) continue; state = 1; } else { state = 0; } sb.Append (text[i]); } text = sb.ToString (); // Favoriteアイコン ToggleButton favBtn = v.CreateFavoriteButton (s); favBtn.Margin = new Thickness (0, 0, 3, 0); inlines.Add (favBtn); // 名前を追加 RoutedEventHandler defLinkHandler = new RoutedEventHandler (v.Hyperlink_Click); DependencyProperty nameFg = TwitterStatusViewer.NameForegroundProperty; inlines.Add (v.CreateHyperlink (s.User.ScreenName, "/" + s.User.ScreenName, nameFg, FontWeights.Bold, defLinkHandler)); inlines.Add (" "); // 本文を追加 v.CreateTweetBody (text, inlines); // 返信情報を追加 if (!string.IsNullOrEmpty (s.InReplyToScreenName)) { inlines.Add (v.CreateTextBlock (" in reply to ", FontWeights.Normal, nameFg)); inlines.Add (v.CreateHyperlink ("@" + s.InReplyToScreenName, "/" + s.InReplyToScreenName + (s.InReplyToStatusId == 0 ? string.Empty : "/status/" + s.InReplyToStatusId.ToString ()), nameFg, FontWeights.Bold, defLinkHandler)); } if (s != s1) { inlines.Add (v.CreateTextBlock (" RT by ", FontWeights.Normal, nameFg)); inlines.Add (v.CreateHyperlink ("@" + s1.User.ScreenName, "/" + s1.User.ScreenName, nameFg, FontWeights.Bold, defLinkHandler)); } }
protected override void Render () { InlineCollection inlines = Inlines; inlines.Clear (); TwitterStatusViewer v = Owner; if (v == null) return; Status s = v.DataContext as Status; if (s == null) return; Status s1 = s; if (s.RetweetedStatus != null) s = s.RetweetedStatus; FontWeight defWeight = this.FontWeight; RoutedEventHandler defLinkHandler = new RoutedEventHandler (v.Hyperlink_Click); DependencyProperty nameFg = TwitterStatusViewer.NameForegroundProperty; Inlines.Add (v.CreateHyperlink (s.User.ScreenName + " [" + s.User.Name + "]", "/" + s.User.ScreenName, nameFg, defWeight, defLinkHandler)); if (!string.IsNullOrEmpty (s.InReplyToScreenName)) { Inlines.Add (v.CreateTextBlock (" in reply to ", FontWeights.Normal)); Inlines.Add (v.CreateHyperlink ("@" + s.InReplyToScreenName, "/" + s.InReplyToScreenName + (s.InReplyToStatusId == 0 ? string.Empty : "/status/" + s.InReplyToStatusId.ToString ()), nameFg, defWeight, defLinkHandler)); } if (s != s1) { Inlines.Add (v.CreateTextBlock (" retweeted by ", FontWeights.Normal)); Inlines.Add (v.CreateHyperlink ("@" + s1.User.ScreenName, "/" + s1.User.ScreenName, nameFg, defWeight, defLinkHandler)); } if (s.Source != null) { int p1 = s.Source.IndexOf ('>'); int p2 = s.Source.IndexOf ('<', Math.Max (0, p1)); string appName = s.Source; if (p1 >= 0 && p2 > 0) appName = s.Source.Substring (p1 + 1, p2 - p1 - 1); p1 = s.Source.IndexOf ('\"'); p2 = s.Source.IndexOf ('\"', Math.Max (0, p1 + 1)); Inlines.Add (v.CreateTextBlock (" from ", FontWeights.Normal)); if (p1 >= 0 && p2 > 0) { Inlines.Add (v.CreateHyperlink (appName, s.Source.Substring (p1 + 1, p2 - p1 - 1), nameFg, defWeight, defLinkHandler)); } else { Inlines.Add (appName); } } Inlines.Add (v.CreateTextBlock (" (" + s.CreatedAt.ToString ("MM/dd HH:mm:ss") + ")", FontWeights.Normal)); }
static void IconSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TwitterStatusViewer self = (TwitterStatusViewer)d; self.IconVisibilityCheck(); }