2010-12-02 29 views
0

J'ai ce problème. J'ajoute des images (sourires) dans le contrôle richTextBox de Extended WPF Toolkit.RichTextBox avec des images - problème avec l'interlignage

En fonction de la conversion de texte simple en texte avec des images, j'ai défini la hauteur de ligne du paragraphe et ce paragraphe je l'ajoute aux blocs de richTextBox. Mais voici:

private void RpTextToTextWithEmoticons(string msg) 
{ 
    //set line height 
    var para = new Paragraph {LineHeight = 40}; 

    var r = new Run(msg); 

    para.Inlines.Add(r); 

    string emoticonText = GetEmoticonText(r.Text); 

    //if paragraph does not contains smile only add plain text to richtextbox rtb2 
    if (string.IsNullOrEmpty(emoticonText)) 
    { 
     RtbConversation.Document.Blocks.Add(para); 
    } 
    else 
    { 
     while (!string.IsNullOrEmpty(emoticonText)) 
     { 

      TextPointer tp = r.ContentStart; 

      // keep moving the cursor until we find the emoticon text 
      while (!tp.GetTextInRun(LogicalDirection.Forward).StartsWith(emoticonText)) 

       tp = tp.GetNextInsertionPosition(LogicalDirection.Forward); 

      // select all of the emoticon text 
      var tr = new TextRange(tp, tp.GetPositionAtOffset(emoticonText.Length)) { Text = string.Empty }; 

      //relative path to image smile file 
      string path = _mappings[emoticonText]; 

      var image = new Image 
      { 
       Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute)), 
       Width = 30, 
       Height = 30, 
      }; 

      //insert smile 
      new InlineUIContainer(image, tp); 

      if (para != null) 
      { 
       var endRun = para.Inlines.LastInline as Run; 

       if (endRun == null) 
       { 
        break; 
       } 
       else 
       { 
        emoticonText = GetEmoticonText(endRun.Text); 
       } 

      } 
     } 
     RtbConversation.Document.Blocks.Add(para); 
    } 
} 

Mais si j'ajoute de nouveaux paragraphes aux blocs, tous les paragraphes ont des hauteurs/espacements différents. J'ai besoin de hauteur/spaccing entre chaque paragraphe, quelque chose comme le chat dans skype.

Mon problème, vous pouvez voir sur l'image: alt text

Où peut-être un problème, je suis impuissant. Merci pour toute avance.

Répondre