New to Telerik UI for WPFStart a free 30-day trial

Loading Data from XML

Updated on Sep 24, 2025

In order to bind the RadGridView to a XML you will need to convert the XML to a collection and then to bind that collection using the ItemsSource property of RadGridView. This tutorial will show you how to do this.

The final result should look like the snapshot below:

Telerik WPF DataGrid PopulatingWithDataLoadFromXml 010

  • Below is a simple XML declaration, used in this tutorial:
XAML
	<Items>
	    <XmlNodeItem Team="Barcelona" Country="Spain"/>
	    <XmlNodeItem Team="Juventus" Country="Italy"/>
	    <XmlNodeItem Team="Inter" Country="Italy"/>
	    <XmlNodeItem Team="Ac Milan" Country="Italy"/>
	    <XmlNodeItem Team="Real M" Country="Spain"/>
	    <XmlNodeItem Team="Arsenal" Country="England"/>
	    <XmlNodeItem Team="Manchester U" Country="England"/>
	    <XmlNodeItem Team="Bayern" Country="Germany"/>
	    <XmlNodeItem Team="Porto" Country="Portugal"/>
	    <XmlNodeItem Team="Liverpool" Country="England"/>
	    <XmlNodeItem Team="Ajax" Country="Holland"/>
	    <XmlNodeItem Team="Olimpic M" Country="France"/>
	</Items>
  • Create a new class named XmlNodeItem. The class is pretty simple and it represents a separate node from the XML document. Its properties are Team and Country. Both of the properties are of type string. Here is the source code:
C#
	public class XmlNodeItem
	{
	    [XmlAttribute(AttributeName = "Team")]
	    public string Team
	    {
	        get;
	        set;
	    }
	    [XmlAttribute(AttributeName = "Country")]
	    public string Country
	    {
	        get;
	        set;
	    }
	}
  • Create a new class named XmlNodeItemList, which derives from ObservableCollection of XmlNodeItem. This is a collection that will be created from the XML file. RadGridView will be bound to this collection.
C#
	[XmlRoot(ElementName = "Items")]
	public class XmlNodeItemList : ObservableCollection<XmlNodeItem>
	{
	    public void AddRange(IEnumerable<XmlNodeItem> range)
	    {
	        foreach (XmlNodeItem node in range)
	        {
	            this.Add(node);
	        }
	    }
	}
  • Create a new class named RadGridViewXmlDataSource, which derives from XmlNodeItemList. Practically, this will be the data source (the model) for the RadGridView. The class takes a path to the XML file and deserialize the data in the private method RetrieveData.
C#
	public class RadGridViewXmlDataSource : XmlNodeItemList
	{
	    private string source;
	    public string Source
	    {
	        get
	        {
	            return this.source;
	        }
	        set
	        {
	            this.source = value;
	            AddRange(RetrieveData(Application.GetResourceStream(new Uri(value, UriKind.Relative)).Stream));
	            AddRange(RetrieveData(File.Open(value, FileMode.Open)));
	        }
	    }
	    private XmlNodeItemList RetrieveData(Stream xmlStream)
	    {
	        XmlSerializer serializer = new XmlSerializer(typeof(XmlNodeItemList));
	        StreamReader reader = new StreamReader(xmlStream);
	        XmlNodeItemList list = (XmlNodeItemList)serializer.Deserialize(reader);
	        return list;
	    }
	}
  • The next step is to declare the RadGridViewXmlDataSource as a resource in your application.
XAML
	<UserControl.Resources>
	    <local:RadGridViewXmlDataSource x:Key="DataSource" Source="RadGridViewBindingToXml.xml"/>
	    <XmlDataProvider x:Key="loadingDataFromXml">
	        <x:XData>
	            <!-- #region gridview-loading-data-from-xml_0 -->
	            <Items>
	                <XmlNodeItem Team="Barcelona" Country="Spain"/>
	                <XmlNodeItem Team="Juventus" Country="Italy"/>
	                <XmlNodeItem Team="Inter" Country="Italy"/>
	                <XmlNodeItem Team="Ac Milan" Country="Italy"/>
	                <XmlNodeItem Team="Real M" Country="Spain"/>
	                <XmlNodeItem Team="Arsenal" Country="England"/>
	                <XmlNodeItem Team="Manchester U" Country="England"/>
	                <XmlNodeItem Team="Bayern" Country="Germany"/>
	                <XmlNodeItem Team="Porto" Country="Portugal"/>
	                <XmlNodeItem Team="Liverpool" Country="England"/>
	                <XmlNodeItem Team="Ajax" Country="Holland"/>
	                <XmlNodeItem Team="Olimpic M" Country="France"/>
	            </Items>
  • Update your RadGridView declaration - set the ItemsSource property.
XAML
	<telerik:RadGridView x:Name="radGridView" ItemsSource="{Binding Source={StaticResource DataSource}}"/>

Run your demo, the result can be seen on the next picture:

Telerik WPF DataGrid PopulatingWithDataLoadFromXml 020

f you need to define the columns manually read the topic Defining Columns.

See Also

In this article
See Also
Not finding the help you need?
Contact Support