The Binding syntax, {Binding /}
, works in WPF but does not work at all in Silverlight 3:
<ContentControl Content="{Binding MyCollection}">
<ContentControl.ContentTempla开发者_如何学编程te>
<DataTemplate>
<ContentControl Content="{Binding /}" />
</DataTemplate>
</ContentControl.ContentTemplate>
</ContentControl>
What's the way to approach this in Silverlight?
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}" />
I think you want {Binding}
or {Binding .}
, either of which do the same thing.
精彩评论