tags:

views:

42

answers:

1

Hello all !

I have a DataGrid that must contain a DataTemplate that should be programmatically defined in code.

This DataTemplate will contain a random number of DataGrids with a random number of columns that will be binded twoway, depending on what I have in the database. This grids will be putted in a StackPanel that is oriented horizontaly.

I know that in Silverlight I have the XamlReader but this is no helpful to me because it will be very hard to build the string that I need to construct the xaml DataTemplate.

Are there any other solutions?

If not, please someone ask the people from Microsoft to implement this functionality in the next .net framework.

A: 

Creating DataTemplate in code behind is not possible in Silverlight :(

Alternatively, you can do this by using Converters, ItemsControl.

Have a DataTemplate with ItemsControl. Bind this to a converter which returns an ObservableCollection. In the converter create the data grids with required number of columns as you like. The Input you supply could be like Enumerable dictionary contains the random data grid's columns and data.

HTH

Avatar
Thank you for your answer.
Alex