带有 ItemsPresenter 的 WPF FlowDocument

发布于 2024-10-20 08:14:15 字数 2696 浏览 6 评论 0原文

我正在使用此处找到的可绑定 FlowDocument 项目控件:

http://msdn.microsoft。 com/en-us/magazine/dd569761.aspx

它的效果与广告中的一样完美;然而,我希望能够扩展它。我希望能够为 ItemsPanel 指定 ItemsPresenter,就像为 ItemsControl 指定 ItemsPresenter 一样。我的目标是为表格添加页脚。

使用网站上的示例:

<flowdoc:ItemsContent ItemsSource="{Binding Source=  {StaticResource  DataSource},XPath=FortressGuys/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>

                <TableRowGroup>

                <!-- ITEMS PRESENTER -->

                </TableRowGroup>

                <TableRowGroup>
                    <TableRow>
                       <TableCell>
                         <Paragraph>My Amazing Footer</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>

最终看起来像这样:

First Name   Last Name
----------------------
Nancy        Davolio
Andrew       Fuller
----------------------
My Awesome Footer

有谁知道这是如何实现的?

I am using the bindable FlowDocument items control found here:

http://msdn.microsoft.com/en-us/magazine/dd569761.aspx

It works perfectly as advertised; however, I was hoping to expand on it. I want to be able to specify an ItemsPresenter for the ItemsPanel, the same way you would for an ItemsControl. My goal is to include a footer for the table.

Using the example on the site:

<flowdoc:ItemsContent ItemsSource="{Binding Source=  {StaticResource  DataSource},XPath=FortressGuys/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>

                <TableRowGroup>

                <!-- ITEMS PRESENTER -->

                </TableRowGroup>

                <TableRowGroup>
                    <TableRow>
                       <TableCell>
                         <Paragraph>My Amazing Footer</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>

Which would ultimately look something like this:

First Name   Last Name
----------------------
Nancy        Davolio
Andrew       Fuller
----------------------
My Awesome Footer

Does anyone know how this would be accomplished?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2024-10-27 08:14:15

进一步查看后,我找到了答案。 IsItemsHost 属性告诉控件将项目放置在何处。

 flowdoc:Attached.IsItemsHost="True"

从第一个 TableRowGroup 中删除该属性并将其添加到第二个行组:

            <TableRowGroup flowdoc:Attached.IsItemsHost="True">

            <!-- ITEMS PRESENTER -->

            </TableRowGroup>

After reviewing it further, I found the answer. The IsItemsHost attribute tells the control where to place the items.

 flowdoc:Attached.IsItemsHost="True"

Remove that attribute from the first TableRowGroup and add it to the second row group:

            <TableRowGroup flowdoc:Attached.IsItemsHost="True">

            <!-- ITEMS PRESENTER -->

            </TableRowGroup>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文