我有这个问题。我从 Extended WPF Toolkit 将图像(微笑)添加到 richTextBox 控件中。
在将简单文本转换为带有图像的文本的函数中,我设置了行高 段和这段我添加到 richTextBox block 。这是它:
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);
}
}
但是如果我向 block 中添加新段落,所有段落都有不同的行高/间距。我需要单个段落之间的 constat 行高/间距,就像在 Skype 中聊天一样。
我的问题你可以在图片上看到:
哪里会出问题,我很无奈。感谢您的任何预付款。
最佳答案
关于wpf - 带有图像的 RichTextBox - 行距问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4333806/