I have an app that receives XML from a server. I want to bind the data to a data grid and it would be grate if the grid auto generated the columns. So far I have tried to this much in my code.
XAML page:
<data:DataGrid x:Name='Status' ItemsSource='{Binding}' AutoGenerateColumns='True'> </data:DataGrid>
Code behind for the page:
void Status_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { XElement recordSet = XElement.Load(e.Result); CamerasStatusTabDataGrid.ItemsSource = recordSet.Elements('Status'); }
XML from the server:
<StatusReport> <Status Description='Spilled Coffe on Server' Date='2/5/2009' /> <Status Description='Mice in Copier' Date='4/3/2008' /> <Status Description='Helped User Find Any Key' Date='6/2/2008' /> </StatusReport>
What I am looking to do is to have the status be a row in the grid with ‘Description’ and ‘Date’ being columns.
A good way to do this is using Linq to Xml, the following is a full example:
Page.xaml:
Page.xaml.cs:
Make sure you add a reference to the System.Xml.Linq assembly. This produces the output you were looking for with a Status for every row in the grid with ‘Description’ and ‘Date’ as columns.
alt text http://www.freeimagehosting.net/uploads/aa3f9978fc.png