I'm developing a Silverlight application, and want to set the ItemsSource
of a ListBox
to ObeservableCollection<XElement>
and still be able to use the Binding Path=Element[name].Value
syntax to get values for a data template. I can get the binding successfully, but the Element[] syntax is not working. It just renders empty. For example, this does not work:
<DataTemplate x:Key="SearchResultsTemplate">
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Element[key].Value}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
But oddly, something like this does render content, which tells me everything is bound to some degree, but something is keeping me from using the Element dynamic property:
<DataTemplate x:Key="SearchResultsTemplate">
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=FirstNode}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
What am I doing wrong?