Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends, I am using a WPF Flowdocument for viewing data.
I want to bind Flowdocument Dynamically with the database through DataTable to show the data in a formatted manner.
But unfortunately it is not showing me the data.
Following is my Flowdocument
XML
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           
              ColumnWidth="400" FontSize="14" FontFamily="Georgia">
    <Table DataContext="{Binding}">
        
        <TableRowGroup Paragraph.TextAlignment="left">
            <TableRow FontWeight="Bold" >
                <TableCell>
                    <Paragraph>
                        <TextBlock Text="{Binding Path=Name}" />
                       
                    </Paragraph>
                </TableCell>
                <TableCell>
                    <Paragraph>
                        <TextBlock Text="{Binding Path=Age}" />
                       
                    </Paragraph>
                </TableCell>
            </TableRow>
           
        </TableRowGroup>
    </Table>

   
</FlowDocument>


I am binding this Flowdocument wiith an DataTable
C#
private DataTable DataTableC()
        {
            DataTable dt = new DataTable("TestData");
            dt.Columns.Add(new DataColumn("Name", typeof(string)));
            dt.Columns.Add(new DataColumn("Age", typeof(int)));

            DataRow dr = dt.NewRow();
            dr[0] = "Demo1";
            dr[1] = 16;
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "Demo2";
            dr[1] = 18;
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "Demo3";
            dr[1] = 22;
            dt.Rows.Add(dr);

            return dt;
        }


And Giving the Data context to the Flow document as follows
C#
FlowDocument document = null;
           document = Application.LoadComponent(new Uri("FlowDocument1.xaml",UriKind.Relative)) as FlowDocument;
           this.WriteXPS(document);
           document.DataContext = DataTableC();


Unfortuantely it is not getting binded.
Any help will be highly appreciated.
Thanks in Advance
Posted

Open-Source WPF Reporting Engine[^]
Using COdeRespon.Reports.dll we can make a dynamic FlowDocumentReport
 
Share this answer
 
v2
Comments
VJ Reddy 31-May-12 4:42am    
Good alternative. 5!
VJ Reddy 31-May-12 4:45am    
Edit: Link earlier pointing to this page is corrected.
C#
document.DataContext = DataTableC().DefaultView;


[Edit]

The reason is that the FlowDocument control does not support DataBinding as explained here http://msdn.microsoft.com/en-us/magazine/dd569761.aspx[^]
"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."
A work around is given at the above reference. I think it may be helpful.
 
Share this answer
 
v3
Comments
WaseemSiddiqui 31-May-12 3:44am    
Sir, I have tried this but it didn't worked
WaseemSiddiqui 31-May-12 4:10am    
Thank you very much Sir. I got it.
VJ Reddy 31-May-12 4:15am    
You're welcome and thank you for accepting the solution :)
P.Salini 31-May-12 4:27am    
my 5
VJ Reddy 31-May-12 4:46am    
Thank you, P.Salini :)
Refer Similar discussion[^], see if you get some help from it..
 
Share this answer
 
Comments
WaseemSiddiqui 31-May-12 3:44am    
Sir its a complete different way. I just want to bind a Datable to the flow report.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900