Xceed Toolkit Plus for WPF v4.6 Documentation
Binding to a LINQ query (XML)

The following example demonstrates how to bind a grid to an XML query on an XDocument that loads the XML version of the Orders table of the Northwind database.

The content of the resulting grid will not be editable.
XAML
Copy Code
<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
  <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                    Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}},
                                     Path=XmlData}"/>
  </Grid.Resources>
 
  <xcdg:DataGridControl x:Name="OrdersGrid"
                       ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>
</Grid>

The following code provides the implementation for the XmlData property, which returns the query result.

VB.NET
Copy Code
Public ReadOnly Property XmlData() As IEnumerable
  Get
    Dim document As XDocument = App.NorthwindDocument
    Dim data As IEnumerable = From order In document.Element("dataroot").Descendants("Orders") _
                              Select New With {.ShipCountry = order.Element("ShipCountry").Value, _
                                .ShipCity = order.Element("ShipCity").Value, _
                                .ShipAddress = order.Element("ShipAddress").Value, _
                                .ShipName = order.Element("ShipName").Value, _
                                .Freight = order.Element("Freight").Value}
    Return data
  End Get
End Property
C#
Copy Code
public IEnumerable XmlData
{
 get
 {
   XDocument document = App.NorthwindDocument;
   IEnumerable data = from order in document.Element( "dataroot" ).Descendants( "Orders" )
                      select new
                      {
                        ShipCountry = order.Element( "ShipCountry" ).Value,
                        ShipCity = order.Element( "ShipCity" ).Value,
                        ShipAddress = order.Element( "ShipAddress" ).Value,
                        ShipName = order.Element( "ShipName" ).Value,
                        ShipVia = order.Element( "ShipVia" ).Value,
                        Freight = order.Element( "Freight" ).Value
                      };
   return data;
 }
}