views:

85

answers:

2

I've been trying to bind XML (via an XElement) to a DataGrid dynamically in Silverlight (specifically Silverlight 4, but any solutions in SL3 would be fine too) but have been unable to do so. I hope to do this dynamically (ie - no rigid business objects to represent the XML).

What I'm hoping for in the end is a way to bind to any XElement containing arbitrary XML, and then use some sort of IConverter to transform the XElement into something the DataGrid can bind to - and just "know" how to auto-generate columns and rows from the converted object.

<sdk:DataGrid 
    ItemsSource="{Binding Source={StaticResource MyViewModel}, 
    Path=MyXElement, Converter={SomeConverter}}" AutoGenerateColumns="True">

If possible, I'd like to be able to utilize some sort of reusable declarative component (trying to avoid code-behind on actual Views).

I've tried using DynamicObjects, but the DataGrid can't figure out its properties. Any other suggestions would be welcome. Thanks.

A: 

Take a look on the following link. It may be a good start: http://www.scottlogic.co.uk/blog/colin/2010/03/binding-a-silverlight-3-datagrid-to-dynamic-data-via-idictionary-updated/

Klinger
i was hoping for something that would dynamically figure out the data structure, since my XML won't explicitly layout the structure in rows and columns.
programatique
A: 
Klinger