I want to add a column programatically to my datagrid and bind it.
I have tried following examples on the web but cant get the data do be displayed.
I did have it working with columns declared in the xaml.
Here is the datagrid Xaml declaration:
<DataGrid Grid.Row="0" x:Name="dtgMain" AutoGenerateColumns="False" ItemsSource="{Binding}" RowHeight="25" SizeChanged="dtgMain_SizeChanged"></DataGrid>
Here is where I set the datacontext for the datagrid:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(response);
provider.Document = doc;
provider.XPath = "/moo/response/data/load/panel";
dtgMain.DataContext = provider;
Here is where I add the column:
DataGridTextColumn dc = new DataGridTextColumn();
dc.Binding = new Binding("panelCode");
dc.Header = "Job Number";
dtgMain.Columns.Add(dc);
And here is an example of the xml:
<moo>
<response>
<data>
<load count="2">true
<panel index="10">
<panelCode>100072
</panelCode>
</panel>
</load>
</data>
</response>
</moo>