Binding DataField to a collection

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}”/>

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>

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>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s