在C#WPF文字环绕图像周围或连接两个的TextBlocks [英] Wrapping text around an image or linking two TextBlocks in C# WPF

查看:200
本文介绍了在C#WPF文字环绕图像周围或连接两个的TextBlocks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个程序,显示文本和在同一窗口中的图像。该图像是在屏幕的左上角和文本将开始它的右边,然后继续向下图像的下方。

I am creating a program that shows text and an image in the same window. The Image is in the top-left corner of the screen and the Text will begin to the right of it, and then continue down below the image.

目前,我试图为取两的TextBlocks(一个图像的右边,一个下面的图片和第一文本块两者)并希望有文本继续从一个街区到另一个。这是一种理想的方法,如果是的话,我会怎么做呢?有没有更好/更简单的方法比这还是我可以只用一个对象呢?谢谢,

Currently, what I am trying is to take two TextBlocks (one to the right of the image and one below both the image and the first textblock) and want to have the text continue from one block to the other. Is this an ideal approach, and if so, how would I do it? Is there a better/easier way than this or can I do it with just one object? Thanks,

安德鲁

推荐答案

我不建议使用的TextBlocks实现这一类型的布局。至于基伦表明,一个的FlowDocument将是理想的这种类型的设计。看看此XAML片段,并使用带有段落元素的FlowDocument和包含图像的浮子元件所产生的WPF应用程序截图:

I would not recommend using TextBlocks to achieve this type of layout. As Kieren suggests, a FlowDocument would be ideal for this type of a design. Take a look at this XAML snippet and the resulting WPF app screenshot using a FlowDocument with a Paragraph element and a Floater element containing an image:

<Grid>
    <FlowDocumentScrollViewer>
        <FlowDocument>                
            <Paragraph>
                <Floater Width="130" HorizontalAlignment="Left" Margin="0,0,5,5" Padding="3">
                    <BlockUIContainer>
                        <Image Source="/FlowDocumentTest;component/dog.png" Width="100" /> 
                    </BlockUIContainer>
                </Floater>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
                Suspendisse et diam felis. Vestibulum ac nisl mi. 
                Etiam varius velit lobortis nibh vestibulum nec consequat velit pellentesque. 
                Cras commodo libero placerat nulla dapibus eget porttitor ligula tempor. 
                Donec nisl massa, congue et pretium sit amet, feugiat vel est. 
                Nulla dapibus metus in justo pulvinar sit amet viverra lorem rhoncus. 
                Integer placerat interdum massa et mattis.</Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>
</Grid>

这篇关于在C#WPF文字环绕图像周围或连接两个的TextBlocks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆