Category / Section
How to parse XML file and set as ItemsSource for SfDataGrid?
1 min read
To parse the XML file include it as an EmbeddedResource in the portable project. To set data from the XML as ItemsSource of SfDataGrid, parse the XML data as stream and Deserialize the stream into a Collection using XmlSerializer.
Refer the below code example in which data from an XML file is parsed and set as ItemsSource for the SfDataGrid.
public MainPage() { InitializeComponent(); var assembly = typeof(MainPage).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream("XMLfileItemsSource.Repository.xml"); ObservableCollection<OrderInfo> OrdersInfo; var serializer = new XmlSerializer(typeof(ObservableCollection<OrderInfo>)); OrdersInfo = (ObservableCollection<OrderInfo>)serializer.Deserialize(stream); dataGrid.ItemsSource = OrdersInfo; }
On executing the above code the below output is obtained.
Sample Link:
How to parse XML file and set as ItemsSource for SfDataGrid?