Articles in this section
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()
    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?


Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied