在WPF RichTextBox中插入图像

时间:2009-02-10 16:38:14

标签: wpf richtextbox image-formats

您好我使用以下代码插入文本和图像,但我想在MSWord

中插入图像“在文本后面”作为图像>调整文本属性
{
            int numeroInforme = Convert.ToInt32(txtNroInforme.Text);
            List<informeMedico> lstInformes = getInformeMedico(numeroInforme);


            FlowDocument mcFlowDoc = new FlowDocument();

            Paragraph para = new Paragraph();

            foreach (informeMedico info in lstInformes)
            {
                var signatureOne = BinaryImageConverter(info.firma1);
                var signatureTwo = BinaryImageConverter(info.firma2);

                para.Inlines.Add(new Run("RM Nro:" + "\t" + info.numeroinforme.ToString()));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run("Sr. Dr.  :" + "\t" + info.medicoCompleto.ToString()));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run("NOMBRE :" + "\t" + info.pacienteCompleto.ToString()));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run("EXAMEN :" + "\t" + info.estudioExamenNombre.ToString()));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run("FECHA :" + "\t" + info.fechainforme.ToString()));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run(info.tecnica));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run(info.hallazgo));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(new Run(info.conclusion));
                para.Inlines.Add(new Run("\n\n"));

                para.Inlines.Add(signatureOne);
                para.Inlines.Add(signatureTwo);
            }

            mcFlowDoc.Blocks.Add(para);

            mainRTB.Document = mcFlowDoc;


        }

提前致谢

1 个答案:

答案 0 :(得分:2)

您可以将BackgroundParagraph个人的Runs设置为ImageBrush

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
        <FlowDocument x:Key="document">
            <Paragraph>
                <Paragraph.Background>
                    <ImageBrush ImageSource="http://sipi.usc.edu/database/misc/4.1.01.tiff" Stretch="UniformToFill"/>
                </Paragraph.Background>
                <Run Foreground="White" Text="this is some text"/>
                <LineBreak/>
                <Run Foreground="White" Text="and some more text"/>
            </Paragraph>
        </FlowDocument>
    </Grid.Resources>
    <FlowDocumentReader Document="{StaticResource document}"/>
</Grid>