wpf - 带有图像的 RichTextBox - 行距问题

标签 wpf richtextbox spacing css

我有这个问题。我从 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 中聊天一样。

我的问题你可以在图片上看到: alt text

哪里会出问题,我很无奈。感谢您的任何预付款。

最佳答案

关于wpf - 带有图像的 RichTextBox - 行距问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4333806/

相关文章:

c# - Caliburn.Micro 嵌套 ViewModels 最佳实践

C# RichTextBox 文本 block 选择

javascript - 如何创建一个提取不同长度字符串的中间到末尾的函数?

wpf - 为什么 RichTextBox 的 MaxLength 属性在 WPF 中不起作用?

wpf - 如何一次折叠所有XAML代码节?

c# - 如何在线程完成时获取返回值

C# - 从 RichTextBox 和 TextBox 添加两个数字

c# - 更改 RichTextBox 中的链接颜色

html - 如何调整工具栏中元素之间的间距?

CSS,连续图片库,每张图片之间的空间,