Click here to Skip to main content
15,939,960 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
<FlowDocument xmlns=""
              ColumnWidth="400" FontSize="14" FontFamily="Georgia">
    <Table DataContext="{Binding}">
        <TableRowGroup Paragraph.TextAlignment="left">
            <TableRow FontWeight="Bold" >
                        <TextBlock Text="{Binding Path=Name}" />
                        <TextBlock Text="{Binding Path=Age}" />


I am binding this Flowdocument wiith an DataTable
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;
            dr = dt.NewRow();
            dr[0] = "Demo2";
            dr[1] = 18;
            dr = dt.NewRow();
            dr[0] = "Demo3";
            dr[1] = 22;

            return dt;

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

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

Open-Source WPF Reporting Engine[^]
Using COdeRespon.Reports.dll we can make a dynamic FlowDocumentReport
Share this answer
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.
document.DataContext = DataTableC().DefaultView;


The reason is that 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."
A work around is given at the above reference. I think it may be helpful.
Share this answer
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
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