我有这个问题。我将图像(微笑)添加到Extended WPF Toolkit的richTextBox控件中。
在将简单文本转换为带图像的文本的功能中,我设置了行高 段落和本段我添加到richTextBox块。这是它:
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);
}
}
但如果我向块添加新段落,则所有段落都有不同的行高/间距。我需要在各个段落之间使用constat行高/间隔,比如skype中的聊天。
我可以在图片上看到我的问题:
哪里可能有问题,我很无奈。感谢任何进展。