我在WPF中的文档布局有哪些选择?

ycl*_*ine 9 .net wpf flowdocument

使用WPF的FlowDocument,我已经遇到了一些需要更多控制文档布局的情况,从简单的事物(页眉和页脚)到更复杂的(脚注,杂志风格的故事流)到更复杂的(带有关键设备的文学文本 - 我的实际要求之一).

但是,据我所知,我唯一的选择是:

A.使用FlowDocument并失去对布局的所有控制权.

B.使用TextFormatter从头开始编写所有内容.

A不是我的选择,B需要实现几十种方法,更重要的是,失去了FlowDocument及其相关Viewers的强大功能.

我的问题是:

是否有任何替代方案可以让我利用FlowDocument的功能,它涵盖了我90%的布局需求,并且只编写实现其他10%所需的代码?

编辑:FlowDocument的可重排方面对我来说至关重要.我知道我要求可回流内容和精确控制布局,这有点矛盾.但是,我知道它可以完成 - 我使用TextFormatter编写了一个简单的实现来完成我想要的东西,但我更倾向于使用FlowDocument和某种扩展来避免重新实现每个功能.

编辑2:似乎我真正追求的是FlowDocument的内部分页器的一个钩子,所以我可以给它指定一个自定义类的布局.有没有办法做到这一点?

Ed *_*ers 6

WPF中的文本系统主要用于播放用于UI的文本,而不是用于生成带有脚注和标题等的复杂文档.但是,框架已经编写,因此如果要添加自定义功能,则可以.

第一个问题:脚注和与文本一致的内容.WPF提供了两个类来将UIElements放入文本中:InlineUIContainerBlockUIContainer.我会考虑编写自己的自定义控件,专门设计用于脚注或类似的行为,并将其放在这两个类中的一个中.如果你需要更多关于什么接受的信息(链接在页面底部),我在MSDN上找到了这个方便的花花公子关系图表

alt text http://i.msdn.microsoft.com/dynimg/IC66504.png

我不完全确定你的"杂志风格故事流"是什么意思.'FlowDocument'会自动将 - Block派生类(上图中的蓝色)排列到可用空间中,您可以使用FloaterFigure内联元素使文本在对象周围"流动" .您还可以使用FigureFloater为您的页眉和页脚功能.

这是一些示例代码:

    <FlowDocumentScrollViewer>
        <FlowDocument>
            <Paragraph>
                5 green bottles standing on the wall,
                5 green bottles standing on the wall, 
                and if one green bottle was to accidentally fall,
                there would be 4 green bottles standing on the wall;
            </Paragraph>
            <Paragraph>
                4 green bottles standing on the wall,
                4 green bottles standing on the wall, 
                <Floater HorizontalAlignment="Left" Width="250">
                    <BlockUIContainer>
                        <Button>This button is in a Floater</Button>
                    </BlockUIContainer>
                </Floater> 
                and if one green bottle was to accidentally fall,
                there would be 3 green bottles standing on the wall;
            </Paragraph>
            <Paragraph>
                3 green bottles standing on the wall,
                3 green bottles standing on the wall, 
                and if one green bottle was to accidentally fall,
                there would be 2 green bottles standing on the wall;
            </Paragraph>

            <Paragraph>
                2 green bottles standing on the wall,
                2 green bottles standing on the wall,
                and if one green bottle was to accidentally fall,
                <InlineUIContainer>
                    <Button>This Button is inline</Button>
                </InlineUIContainer> 
                there would be 1 green bottle standing on the wall...
            </Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>
Run Code Online (Sandbox Code Playgroud)

您可以Button使用自己的自定义控件替换s(例如带有脚注的内联按钮)

这段代码使这个: DesignerView

我希望有所帮助!我不知道你到底想要做什么,但我认为你仍然可以使用FlowDocument并只使用WPF提供的大量文本操作设备,如果你确实需要额外的功能/布局选项,那么创建一个继承的新类Block或者Inline或其他什么,并在那里写额外的东西,以利用所有的工作.net可以为你做.如果您需要更多信息,可以在MSDN上阅读有关WPF中文本内容的更多信息:

关于如何使用FlowDocument的超长篇文章

WPF中使用的文本内容模型(我从中获取了图像)

玩的开心 :)