C# 如何为RichTextBlock在跑步中添加图像?

C# 如何为RichTextBlock在跑步中添加图像?,c#,wpf,C#,Wpf,我编写了一个小的WPF应用程序,我喜欢将文本预先添加到RichTextBox中,这样最新的东西就可以放在上面了。我写了这篇文章,它很有效: /// <summary> /// Prepends the text to the rich textbox /// </summary> /// <param name="textoutput">The text representing the character informatio

我编写了一个小的WPF应用程序,我喜欢将文本预先添加到RichTextBox中,这样最新的东西就可以放在上面了。我写了这篇文章,它很有效:

    /// <summary>
    /// Prepends the text to the rich textbox
    /// </summary>
    /// <param name="textoutput">The text representing the character information.</param>
    private void PrependSimpleText(string textoutput)
    {
        Run run = new Run(textoutput);
        Paragraph paragraph = new Paragraph(run);

        if (this.RichTextBoxOutput.Document.Blocks.Count == 0)
        {
            this.RichTextBoxOutput.Document.Blocks.Add(paragraph);
        }
        else
        {
            this.RichTextBoxOutput.Document.Blocks.InsertBefore(this.RichTextBoxOutput.Document.Blocks.FirstBlock, paragraph);
        }
    }
//
///将文本前置到富文本框
/// 
///表示字符信息的文本。
私有void PrependSimpleText(字符串文本输出)
{
运行=新运行(文本输出);
段落=新段落(运行);
if(this.RichTextBoxOutput.Document.Blocks.Count==0)
{
this.RichTextBoxOutput.Document.Blocks.Add(段落);
}
其他的
{
this.RichTextBoxOutput.Document.Blocks.InsertBefore(this.RichTextBoxOutput.Document.Blocks.FirstBlock,段落);
}
}

现在我想做一个新版本的功能,可以添加小图像以及。但我还是不知所措-可以添加图像吗

RickTextbox.Document是一个FlowDocument,您几乎可以向其中添加任何实现ContentElement的内容。这包括图像、标签、StackPanel和所有其他WPF收藏夹


查看以了解更多详细信息。

RickTextbox.Document是一个FlowDocument,您几乎可以向其中添加任何实现ContentElement的内容。这包括图像、标签、StackPanel和所有其他WPF收藏夹

查看以了解更多详细信息。

请尝试以下操作:

BitmapImage bi = new BitmapImage(new Uri(@"C:\SimpleImage.jpg"));
Image image = new Image();
image.Source = bi;
InlineUIContainer container = new InlineUIContainer(image);            
Paragraph paragraph = new Paragraph(container); 
RichTextBoxOutput.Document.Blocks.Add(paragraph);
InlineUIContainer是这里的“魔力”。。。您可以向其中添加任何UIElement。如果要添加多个项目,请使用面板包装项目(如StackPanel等)

尝试以下操作:

BitmapImage bi = new BitmapImage(new Uri(@"C:\SimpleImage.jpg"));
Image image = new Image();
image.Source = bi;
InlineUIContainer container = new InlineUIContainer(image);            
Paragraph paragraph = new Paragraph(container); 
RichTextBoxOutput.Document.Blocks.Add(paragraph);

InlineUIContainer是这里的“魔力”。。。您可以向其中添加任何UIElement。如果要添加多个项目,请使用面板包装这些项目(如StackPanel等)

Aha-我无法理解位图->图像->inlineuicontainer->段落内容。谢谢啊哈-我无法理解位图->图像->inlineuicontainer->段落内容。谢谢谢谢,但我已经玩了一段时间,似乎无法获得正确的对象组合使其工作。谢谢,但我已经玩了一段时间,似乎无法获得正确的对象组合使其工作。