This is a migrated thread and some comments may be shown as answers.

[Solved] Binding to XElements

3 Answers 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mikael
Top achievements
Rank 1
Mikael asked on 25 Aug 2009, 01:33 AM
I'm trying to implement a RadGridView-based Silverlight usercontrol which will accept data which is originally generated from DataSets on the server.

In order to do this, I serialize the data and the schema of the DataSet and pass it through the webservice.
On the client, I've managed to extract the schema, and create the correct set of GridViewDataColumn. Each GridViewDataColumn will have their UniqueName set appropriately.

That part works fine, but binding the actual data doesn't work as well.
The code is a little too complex to send, but here's a simple example:
Here's the XML representing the actual data:
<DataSet> 
  <Table> 
    <Id>7f575607-b408-4363-8091-a5ec35ccb359</Id> 
    <ConfigLevel>-2 - InfoWeaver Samples.</ConfigLevel> 
    <Name>Sample Config 1</Name> 
    <Description>Sample Config 1</Description> 
    <Value>123</Value> 
    <DataType>varchar(32)</DataType> 
    <Modified_x0020_by>VM-WSS\Administrator</Modified_x0020_by> 
    <Modified_x0020_at>2009-01-12T14:21:31.657+01:00</Modified_x0020_at> 
  </Table> 
  <Table> 
    <Id>db17b7ab-10d2-4498-ab6d-c0d0ab17f38d</Id> 
    <ConfigLevel>-2 - InfoWeaver Samples.</ConfigLevel> 
    <Name>Sample Config 2</Name> 
    <Description>Sample Config 2</Description> 
    <Value>1</Value> 
    <DataType>bit</DataType> 
    <Modified_x0020_by>VM-WSS\Administrator</Modified_x0020_by> 
    <Modified_x0020_at>2008-11-28T15:23:54+01:00</Modified_x0020_at> 
  </Table> 
...  
</DataSet> 
 
In this case, I have created 8 columns, with UniqueName "Id", "ConfigLevel", "Name", etc.
I then use Linq to XML to extract individual "XElement":s, where is XElement represents a separate row in the table, e.g.:
  <Table> 
    <Id>7f575607-b408-4363-8091-a5ec35ccb359</Id> 
    <ConfigLevel>-2 - InfoWeaver Samples.</ConfigLevel> 
    <Name>Sample Config 1</Name> 
    <Description>Sample Config 1</Description> 
    <Value>123</Value> 
    <DataType>varchar(32)</DataType> 
    <Modified_x0020_by>VM-WSS\Administrator</Modified_x0020_by> 
    <Modified_x0020_at>2009-01-12T14:21:31.657+01:00</Modified_x0020_at> 
  </Table> 
I add each such XElement to an ObservableCollection<XElement> collection, and set the grid's ItemsSource to this collection.

The output is the correct number of columns and rows. The data though is wrong - one column ("Name") contains the text "Table", whereas the "Value" -column contains all elements' text-content (e.g. "7f575607-b408-4363-8091-a5ec35ccb359-2 - InfoWeaver Samples.Sample Config 1Sample Config 1123varchar(32)VM-WSS\Administrator2009-01-12T14:21:31.657+01:00")

I'm sure there's an easy way to do this, but I'm new to both Silverlight and Linq.
Any ideas?

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 26 Aug 2009, 08:30 AM
Hi Fredrik,

Currently we do not support binding to XElements. We will consider implementing this for the future, but I cannot provide an exact time frame. Until then you will have to wrap the data in "normal" business objects and feed a collection of such objects to the ItemsSource.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mikael
Top achievements
Rank 1
answered on 26 Aug 2009, 03:50 PM
Thanks, Ross!

I'm a little surprised to hear this. As I've understood it, the DataGrid supports XElement binding. Also, I thought that the "binding framework" was part of the Silverlight platform, and that it should automatically be available in all binding scenarios.
So, please forgive me for asking this, but are you sure about this?

If you are (and I think you are), how do you recommend me implementing this? Note that I don't know the set of "columns" in the XML-data at design-time.

Thanks!
/Fredrik
0
Rossen Hristov
Telerik team
answered on 28 Aug 2009, 03:33 PM
Hi Fredrik,

We have to do a lot of things so that the grid can be bound to anything, so it's not that simple. The thing is that we need to obtain a type description (i.e. the properties and their types) for the business object and in different cases this is done differently. Consider primitive types, XmlNodes, XElements and so on -- believe me there are a lot of cases. But I would not like to go into much details here.

It's not impossible -- it simply has not been implemented yet and we will do it as soon as possible.

There is one possible workaround I think. My colleague Vladimir Enchev has created a light-weight DataTable implementation for Silverlight which you can create, configure and fill up with data on the fly.
Please, check out his blog post about the DataTable. I think this will help you.

Kind regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Mikael
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Mikael
Top achievements
Rank 1
Share this question
or