Пример #1
0
 static void InsertToken(ICollection<Inline> ic, Token t, TextRenderContext ctx)
 {
     switch (t.tag)
     {
     case TokenTypes.Hyperlink:
         InsertHyperLink(ic, t);
         break;
     case TokenTypes.Name:
         InsertMentionName(ic, t);
         break;
     case TokenTypes.Emotion:
         InsertEmotion(ic, t);
         break;
     case TokenTypes.CopyedFrom:
         InsertCopyedFrom(ic, t,ctx);
         break;
     case TokenTypes.ReplyTo:
         InsertReplyto(ic, t);
         break;
     case TokenTypes.Topic:
         {
             InsertTopic(ic, t);
         }
         break;
     case TokenTypes.Quote:
         {
             InsertQuote(ic, t);
         }
         break;
     case TokenTypes.Writer:
             {
                 InsertWriter(ic, t);
                 break;
             }
     case TokenTypes.Break:
         {
             InsertBreak(ic);
             break;
         }
     //case TokenTypes.End:
     //case TokenTypes.Punctuation:
     //case TokenTypes.Part:
     //case TokenTypes.Reserved:
     default:
         InsertNormal(ic, t);
         break;
     }
 }
Пример #2
0
 private static void InsertTokens(TextBlock textblock, WeiboStatus status, TextRenderContext ctx)
 {
     if (textblock == null)
         return;
     if ((bool)textblock.GetValue(DesignerProperties.IsInDesignModeProperty))
         return;
     if (status == null)
         return;
     textblock.Inlines.Clear();
     var ic = new List<Inline>();
     foreach (var sent in status.tokens)
     {
         InsertToken(ic, sent,ctx);
     }
     textblock.Inlines.AddRange(ic);
     if (textblock.Inlines.Count == 0)
         textblock.Visibility = Visibility.Collapsed;
 }
Пример #3
0
        private static void OnWeiboPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(d))
                return;
            var textblock = (TextBlock)d;
            var status = (WeiboStatus)e.NewValue;
            var ctx = new TextRenderContext();

            InsertTokens(textblock, status, ctx);
        }
Пример #4
0
        private static void InsertCopyedFrom(ICollection<Inline> textblock, Token t, TextRenderContext ctx)
        {
            var name = t.text;
            if (string.IsNullOrEmpty(name))
                return;
            if(!ctx.HasCopyedFromItem)
            {
                ctx.HasCopyedFromItem = true;
                textblock.Add(new LineBreak());
            }
            textblock.Add(new Run("//@"));
            var h = new Hyperlink(new Run(name));
            //h.SetResourceReference(Control.ForegroundProperty, "MetroColorText");
            textblock.Add(h);

            textblock.Add(new Run(":"));
        }