Home > Sivlerlight 3 > Binding DataField to a collection

Binding DataField to a collection

December 10, 2009 lee Leave a comment Go to comments

Here is something I found interesting browsing the silverlight forums. Assuming we are editing a object and we are in editmode in the DataForm

If we want to bind a property to a datafield we do something like

<dataFormToolkit:DataField Label=”FirstName”>
                            <TextBox Text=”{Binding FirstName, Mode=TwoWay}”/>
                        </dataFormToolkit:DataField>

buf if the property is a collection doing something similar wont work( the control will not be enabled)

<dataFormToolkit:DataField Label=”Skills”  >
                            <ListBox  ItemsSource=”{Binding Skills }”></ListBox>
                        </dataFormToolkit:DataField>

looks like we need to do something like this, specify the DataContext on the DataField

<dataFormToolkit:DataField Label=”Skills”  DataContext=”{Binding Skills}” >
                            <ListBox  ItemsSource=”{Binding }”></ListBox>
                        </dataFormToolkit:DataField>


Categories: Sivlerlight 3
  1. No comments yet.
  1. No trackbacks yet.