1

我有一些代码可以绑定到 observablecollection。问题是我只得到一行而不是几行(意味着显示可观察集合中的所有元素)。如何获取可观察集合的所有行?

<FlowDocumentScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" FontFamily="Arial" BorderThickness="0" >
    <FlowDocument>
        <Table Name="myTable" FontFamily="Calibri" BorderThickness="3" BorderBrush="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" DataContext="{Binding}">
            <Table.Columns>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
                <TableColumn/>
            </Table.Columns>
            <TableRowGroup DataContext="{Binding}">
                <TableRow>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Activity_Name}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Data_Type}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run  Text="{Binding Insert_Succeeded}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run  Text="{Binding Insert_Failed}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Update_Succeeded}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Update_Failed}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Delete_Succeeded}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Delete_Failed}"/>
                        </Paragraph>
                    </TableCell>
                    <TableCell>
                        <Paragraph>
                            <Run Text="{Binding Skipped}"/>
                        </Paragraph>
                    </TableCell>
                <TableRow>
            </TableRowGroup>
        </Table>
    </FlowDocument>
</FlowDocumentScrollViewer>
4

1 回答 1

3

FlowDocument 控件不支持 DataBinding,如此处所述

虽然流文档有很多很棒的特性,但是如果您的文档是从动态数据生成的,那么您就有一个问题:流文档中不支持数据绑定。流文档元素(Section、Table、Run、Paragraph 等)是依赖对象,但不定义任何允许您动态更改或生成内容的依赖属性。

上面的链接提供了一个解决方法,这可能对您有所帮助。

于 2013-08-13T02:26:14.033 回答