Home Forums WPF controls Xceed DataGrid for WPF Binding to XML?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #21563 |

    I just started working with this Grid so apologies if this is something obvious that I missed….Is binding to an XML data source not supported? looking through the samples and help I don’t see how to do this. I’d like the control to automatically build a hierarchical set of data in the grid.

    Can someone help?

    Imported from legacy forums. Posted by Tim (had 4540 views)

    Xceed Support
    Member
    Post count: 5658

    Binding to a XML data source is indeed supported.

    The main thing to know about this is that the “AutoCreateColumns” feature of the DataGridControl will not work when using a XML data source, therefore you should set this property to “false” on the DataGridControl.

    Then, all you need to do is to manually create your columns and use a “DisplayMemberBinding” that specifies a “XPath” instead of a “Path”.

    Here is a quick sample on how to get this working:

    <hr>
    <code>
    <Page.Resources>
    <XmlDataProvider x:Key=”rssFeed”
    Source=”http://msdn.microsoft.com/rss.xml&#8221;
    XPath=”rss/channel/item” />

    </Page.Resources>

    <xcdg:DataGridControl ItemsSource=”{Binding Source={StaticResource rssFeed}}”
    AutoCreateColumns=”False”>

    <xcdg:DataGridControl.Columns>
    <xcdg:Column Title=”Title”
    FieldName=”title”
    Width=”200″
    DisplayMemberBinding=”{Binding XPath=title}”/>

    <xcdg:Column Title=”Description”
    FieldName=”description”
    Width=”200″
    DisplayMemberBinding=”{Binding XPath=description}”/>

    <xcdg:Column Title=”Publication Date”
    FieldName=”pubDate”
    Width=”70″
    DisplayMemberBinding=”{Binding XPath=pubDate}”/>

    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>
    </code>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 671 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t have it working yet, but, will it interpret the hierarchical nature of the data and generate columns for the child nodes? if not, How do I define columns for the child records?

    Imported from legacy forums. Posted by Tim (had 461 views)

    Xceed Support
    Member
    Post count: 5658

    As mentioned earlier, when bound to a XML data source, the automatic creation of columns will not work. You will need to manually create the columns and specify the DisplayMemberBinding (with XPath instead of Path) for each of them.

    Using XPath, you can reference something that is deep down within the structure of a node:

    In the example below:
    <code>
    <book>
    <title>My Book Title</title>
    <author>
    <firstName>My Author First Name</firstName>
    <lastName>My Author Last Name</lastName>
    </author>
    </book>

    </code>

    If you want to refer to the Title of the book, then the appropriate XPath is “title”, if you want to refer to the First Name of the Author, then the XPath will be “author/firstName”.

    If you want to display a complex node (such as the Author node, using the XPath “author”), then you’ll need build a CellContentTemplate that will parse the inner XML of the “author” node and display the appropriate content. This will work fine as long as you don’t want to edit the Column.

    The DataGridControl was not designed to edit such complex nodes or XPath expressions that resolve to multiple nodes. If editing the column is not required, I recommend setting the ReadOnly property of the column to “True”.

    However, if you need to edit the content of the column, my suggestion is to Parse the XML into a collection of objects and provide your own Serialization/De-Serialization logic.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 682 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m a newbie trying to use MS Expression Blend to create the XAML that would show some data stored in an XML file in your DataGrid for WPF.

    First off, perhaps you can stop me in my tracks if this is not even possible. Assuming it is, I’m running across several issues that I’d hope you could help me overcome. After reading this thread where it says that you must set the AutoCreateColumns=”False” Blend complains with an error ‘The member “AutoCreateColumns” is not recognized or is not accessible’. Why? I’d added this directly to the XML view since I could not find a way to do it in the Design view.

    Also, could you please make a more detailed explaination/sample/tutorial of how to setup the Datagrid to a hierarchical XML file. IMO, this thread only gives hints as to what is required and a complete picture would go a long way to a newbie like myself. Thanks.

    Regards

    Imported from legacy forums. Posted by Mike (had 5559 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.