Click here to Skip to main content
15,881,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I tap on listBox item i get a SubItem in "selectionChanged" event. I need to get Title as well. How i can achieve it?
C#
public class Data
   {
       public string Title { get; set; }
       public List<SubItem> SubItems { get; set; }
       public Data()
       {
           SubItems = new List<SubItem>();


}
}
XML
<phone:LongListSelector ItemsSource="{Binding DataCollection}" Grid.Row="0">
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Title}" Padding="5" />
                            <TextBlock Text="{Binding ImageSource}" Padding="5"/>
                        </StackPanel>
                        <ListBox ItemsSource="{Binding SubItems}" SelectionChanged="ListBox_SelectionChanged">
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical"/>
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding SubItemTitle}" Margin="0,0,12,0" Padding="10" />
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>
Posted

1 solution

Try the following:
XML
<TextBlock Text="{Binding SubItemTitle}" Margin="0,0,12,0" Padding="10" 
Tag="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type LongListSelector}}, Path=ItemsSource.Title}"/>

I don't have a winphone environment available at this moment, so please test the values for AncestorType and Path.
This should make the title availble through the Tag property of the TextBlock, and therefore accessible from the event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900