views:

290

answers:

3

The Binding syntax, {Binding /}, works in WPF but does not work at all in Silverlight 3:

<ContentControl Content="{Binding MyCollection}">
    <ContentControl.ContentTemplate>
        <DataTemplate>
            <ContentControl Content="{Binding /}" />
        </DataTemplate>
    </ContentControl.ContentTemplate>
</ContentControl>

What's the way to approach this in Silverlight?

+1  A: 

I think you want {Binding} or {Binding .}, either of which do the same thing.

Gabe
+2  A: 

When binding to a collection in WPF, you're actually binding to something that understands the concept of "Current Item".

However in Silverlight what you're binding to doesn't have this concept. So you need to do it yourself.

For example in a MVVM app expose a property.

<ListBox SelectedItem="{Binding MyCurrentItem}" 
         ItemsSource="{Binding MyCollection}"/>
<ContentControl Content="{Binding MyCurrentItem}" />

or do some element binding

<ListBox x:Name="listBox" 
         ItemsSource="{Binding MyCollection}"/>
<ContentControl Content="{Binding SelectedItem, ElementName=listBox}" />
Graeme Bradbury
A: 

good man. i was searching for it too long.

Tiju John