New Posts New Posts RSS Feed: Binding Anonymous Types
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Binding Anonymous Types

 Post Reply Post Reply
Author
burrowsUW View Drop Down
Newbie
Newbie


Joined: 19-Mar-2009
Location: Washington Stat
Posts: 5
Post Options Post Options   Quote burrowsUW Quote  Post ReplyReply Direct Link To This Post Topic: Binding Anonymous Types
    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
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
burrowsUW View Drop Down
Newbie
Newbie


Joined: 19-Mar-2009
Location: Washington Stat
Posts: 5
Post Options Post Options   Quote burrowsUW Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jul-2009 at 10:13am
Thanks ... that worked!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down