views:

41

answers:

1

In a Windows Phone 7 Silverlight application, 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 to have the TextBlock named txtDescription be collapsed by default, but set it to visible when the item is selected. How can I do that (preferably in XAML) ?

+1  A: 

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

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

Matt Lacey