Silverlight ListBox ItemTemplate: Display specific items when selecting an item

In a Silverlight app from Windows Phone 7, I have this ListBox:

<ListBox ItemsSource="{Binding Path=Programs}" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Begin, Converter={StaticResource TimeOfDayConverter}}" Margin="0,0,10,0" Width="46" /> <TextBlock Text="{Binding Title}" FontSize="30" /> </StackPanel> <TextBlock x:Name="txtDescription" Text="{Binding Description}" Margin="56,0" Visibility="Collapsed" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> 

I need the TextBlock named txtDescription collapse by default, but set it visible when the item is selected. How can I do this (preferably in XAML)?

+4
source share
1 answer

You can use VisualStateManager to change what is visible based on SelectionState.

An example of performing similar operations based on selection (but not on the phone) can be found at http://forums.silverlight.net/forums/p/180002/405838.aspx

+3
source

All Articles