我有这个问题。我从 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);
}
}
但是如果我将新段落添加到块中,所有段落都有不同的行高/间距。我需要单个段落之间的 const 行高/间距,例如在 Skype 中聊天。
我的问题你可以在图片上看到:
哪里有问题,我很无奈。感谢任何提前。