使用DataTemplate的FlowDocument [英] FlowDocument using DataTemplate

查看:79
本文介绍了使用DataTemplate的FlowDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在流程文档中创建页面,在该页面中将使用DataTemplates添加页面.我试图通过将ViewModels实例添加到ItemsCollection中来在FlowDocumentScrollViewer中托管的flowDocument中具有ItemsControl. 我遇到的问题是

I want to create pages in a flow document where the pages would be added using DataTemplates. What I tried was to have an ItemsControl in a flowDocument which is hosted in a FlowDocumentScrollViewer by adding instances of ViewModels to the ItemsCollection. The problem I am having is

1.我该如何将段落保存在DataTemplate中?

1. What do I use to hold the paragraphs in a DataTemplate?

 例如:在下面的DataTemplate中包含两个段落的元素应该是什么?

  for eg: What should be the element that holds both paragraphs in the below DataTemplate?

  < DataTemplate DataType = {x:Type MyPage1}>

  <DataTemplate DataType={x:Type MyPage1}>

      < Paragrah BreakPageBefore ="True">

      <Paragrah BreakPageBefore="True">

        .....

        .....

      </Paragraph>

      </Paragraph>

       < Paragraph>

       <Paragraph>

       </Paragraph>

       </Paragraph>

  </DataTemplate

  </DataTemplate

2.除了使用ItemsContainer之外,还有一种更好的方法来执行此操作,以便渲染后我可以将其看起来像单独的页面.

2. Instead of using an ItemsContainer is there a better way to do this so that I can have it look like seperate pages once it is rendered.

添加所有页面后,它应表现为单个文档的页面.

After I add all the pages, it should behave as pages of a single document.

谢谢

  Zest4Quest

  Zest4Quest


推荐答案

嗨Zest4Quest,

Hi Zest4Quest,

>>"我该如何在DataTemplate中保存段落
>>除了使用ItemsContainer之外,还有一种更好的方法来执行此操作,以便在渲染后使它看起来像单独的页面.

>>What do I use to hold the paragraphs in a DataTemplate
>> Instead of using an ItemsContainer is there a better way to do this so that I can have it look like seperate pages once it is rendered.

据我所知,没有内置的方法可以处理此问题,建议您阅读本文:

As far as I know, there is no build-in way to handle this, I would suggest you reading this article:

#使用流文档和数据绑定创建灵活的UI
https://msdn.microsoft.com/en-us/magazine/dd569761.aspx#id0420102

作者创建了自定义的Section类: ItemsContent ,用法:

The author created customized Section class: ItemsContent, the usage:

<FlowDocumentScrollViewer>
            <FlowDocument>
                <flowdoc:ItemsContent ItemsSource="{Binding Source={StaticResource DataSource},XPath=NorthwindNames/Person}" >
                    <flowdoc:ItemsContent.ItemsPanel>
                        <DataTemplate>
                            <flowdoc:Fragment>
                                <Table BorderThickness="1" BorderBrush="Black">
                                    <TableRowGroup flowdoc:Attached.IsItemsHost="True">
                                        <TableRow Background="LightBlue">
                                            <TableCell>
                                                <Paragraph>First name</Paragraph>
                                            </TableCell>
                                            <TableCell>
                                                <Paragraph>Last name</Paragraph>
                                            </TableCell>
                                        </TableRow>
                                    </TableRowGroup>
                                </Table>
                            </flowdoc:Fragment>
                        </DataTemplate>
                    </flowdoc:ItemsContent.ItemsPanel>
                    <flowdoc:ItemsContent.ItemTemplate>
                        <DataTemplate>
                            <flowdoc:Fragment>
                                <TableRow>
                                    <TableCell>
                                        <Paragraph>
                                            <flowdoc:BindableRun BoundText="{Binding XPath=@FirstName}" />
                                        </Paragraph>
                                    </TableCell>
                                    <TableCell>
                                        <Paragraph>
                                            <flowdoc:BindableRun BoundText="{Binding XPath=@LastName}"/>
                                        </Paragraph>
                                    </TableCell>
                                </TableRow>
                            </flowdoc:Fragment>
                        </DataTemplate>
                    </flowdoc:ItemsContent.ItemTemplate>
                </flowdoc:ItemsContent>
            </FlowDocument>
</FlowDocumentScrollViewer>


这篇关于使用DataTemplate的FlowDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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