locked
How to create the Nested Listview in windows store apps RRS feed

  • Question

  • How to create the Nested Listview in windows store apps,If i clidk the parent list i should able to add child list,then it should get displayed in the listview.How xaml code should be written to able design in this format

    amair

    Wednesday, August 7, 2013 9:07 AM

Answers

  • A nested listview:

     protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                List<Rocket> RocketList = new List<Rocket>();
    
                Rocket Rocket1 = new Rocket();
                Rocket1.Name = "My Fun Rocket";
                Rocket1.Guns = new List<Gun>();
                Rocket1.Guns.Add(new Gun() { Name = "SuperLazer"});
                Rocket1.Guns.Add(new Gun() { Name = "CrappyLazer" });
    
                Rocket Rocket2 = new Rocket();
                Rocket2.Name = "My Sad Rocket";
                Rocket2.Guns = new List<Gun>();
                Rocket2.Guns.Add(new Gun() { Name = "RainbowLazer" });
    
                RocketList.Add(Rocket1);
                RocketList.Add(Rocket2);
    
                MainListBox.ItemsSource = RocketList;
            }
     <ListBox x:Name="MainListBox" Width="400" SelectionMode="Single" Height="50">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text=" - "/>
                                <TextBlock Text="{Binding Name}"/>
                            </StackPanel>
                            <ListBox ItemsSource="{Binding Guns}" SelectionMode="Single" Height="50">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="    · "/>
                                            <TextBox Text="{Binding Name}"/>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>



    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, August 7, 2013 6:18 PM
    Moderator