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