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()
{
    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.

C:\Users\suhasini.suresh\AppData\Local\Microsoft\Windows\INetCacheContent.Word\Screenshot_2017-02-13-11-25-57_XMLfileItemsSource.Droid.png

 

Sample Link:

How to parse XML file and set as ItemsSource for SfDataGrid?

 

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