Home Forums WPF controls Xceed DataGrid for WPF Grouping and sorting XML data

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Xceed Support
    Member
    Post count: 5658
    #25860 |

    For those of you who wanted to group and sort xml data, here are 2 classes that will allow you to do it:

    XmlPropertyDescriptor.cs: returns the typed value through its GetValue implementaion, which will allow the items to be sorted and grouped correctly.

    XmlDataGridItemProperty.cs : creates the XmlPropertyDescriptor in its constructor.

    How to use the classes

    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
       <Grid.Resources>
          <XmlDataProvider x:Key=”xmlData”
                                    Source=”Data\Northwind.xml”
                                    XPath=”dataroot/Orders” />

           <xcdg:DataGridCollectionViewSource x:Key=”cvs_xml” Source=”{Binding Source={StaticResource xmlData}}”>
               <xcdg:DataGridCollectionViewSource.ItemProperties>
                  <local:XmlDataGridItemProperty Name=”ShipCountry” DataType=”{x:Type s:String}” Title=”Ship Country”/>
                  <local:XmlDataGridItemProperty Name=”Freight” DataType=”{x:Type s:Double}”/>
                  <local:XmlDataGridItemProperty Name=”OrderDate” DataType=”{x:Type s:DateTime}” />
               </xcdg:DataGridCollectionViewSource.ItemProperties>
          </xcdg:DataGridCollectionViewSource>
        </Grid.Resources>

        <xcdg:DataGridControl x:Name=”XmlGrid” ItemsSource=”{Binding Source={StaticResource cvs_xml}}”/>
    </Grid>

    You will need to rename the file extensions from .txt back to .cs.

    Those of you who are using .NET 3.5, you can also use LINQ to handle your XML data.

    Hope this solves some of the issues a couple of you were having 🙂

    Imported from legacy forums. Posted by Jenny [Xceed] (had 6134 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.