Print Page | Close Window

Binding Anonymous Types

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1365
Printed Date: 22-Sep-2025 at 4:22am


Topic: Binding Anonymous Types
Posted By: burrowsUW
Subject: Binding Anonymous Types
Date Posted: 07-Jul-2009 at 3:56pm
Hi,
 
I am using a query that returns an anonymous type. My query is:
 
        Dim pQuery As EntityQuery = From p In theManager.Products _
                                    Select New With { _
                                    p.ProductNumber, p.Name}
 
I am binding to a DataGrid in the callback using this code:
 
productGrid.ItemsSource = args.Result
 
My DataGrid is defined as follows:
 
        <data:DataGrid x:Name="productGrid"
                           AutoGenerateColumns="False"
                           Height="350">
            <data:DataGrid.Columns>
                <data:DataGridTextColumn Header="Product ID"
                                             Binding="{Binding ProductNumber}"/>
                <data:DataGridTextColumn Header="Product Name"
                                             Binding="{Binding Name}"/>
            </data:DataGrid.Columns>
        </data:DataGrid>
 
The result is not working. The DataGrid is filled with something (the rows get narrower), but there is not text. Any idea what I am doing wrong?
 
bill b



Replies:
Posted By: kimj
Date Posted: 07-Jul-2009 at 7:43pm
Silverlight doesn't support binding to anonymous types (because it supports only public reflection), but you can still do this in DevForce.  You'll need to convert the results into instances of a "dynamic type", something like this:
 
        productGrid.ItemsSource = DynamicTypeConverter.Convert(args.Result)
 
The DynamicTypeConverter class is located in IdeaBlade.Core.


Posted By: burrowsUW
Date Posted: 08-Jul-2009 at 10:13am
Thanks ... that worked!



Print Page | Close Window