I am binding a collection (rss feed) into a list box such as this:
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<HyperlinkButton Content={Binding Title} NavigateUri="{Binding Link}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This works great – the data displays correctly etc. But now when I changed it to use text wrapping, the title is not displaying anymore.
Here is the problematic code.
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<HyperlinkButton NavigateUri="{Binding Link}">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" />
</HyperlinkButton>
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I don’t think it’s the “TextWrapping” attribute that is causing the issue, since I tried without it and it still did not work. So my question is how do you get something like this to work? I just want to display a hyperlink with wrapped bound text. It looks like a fairly simple thing to do – but yet so hard. Help?
I was having the exact same problem and I couldn’t understand why it wasn’t working until I ran across this blog post by Mister Goodcat. In his post he said that because of some optimizations made for the WP7 in Silverlight the basic functionality that works in normal Silverlight does not work correctly for WP7 Silverlight. Instead of using he suggests modifying the Style instead.
I suggest reading his blog post for more information & help.