简体   繁体   中英

How to bind a wpf table to an observablecollection?

I have some code to bind to an observablecollection. The problem is that I just get one row instead of getting several rows (meaning displaying all the elements in the observable collection) . How can I get all the rows for the observable collection?

<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>

The FlowDocument control does not support DataBinding as explained here

While there are many great features in flow documents, if your documents are generated from dynamic data, you have a bit of a problem: there is no support for data binding in flow documents . The flow document elements (Section, Table, Run, Paragraph and the like) are dependency objects, but don't define any dependency properties that would allow you to dynamically change or generate content.

There is a work around given at the above link, which might be helpful for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM