Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here my problem is :

i) List Box 1 has it items when ever click(Tap) the listbox item another listbox2 add to there and show ListBox2(as a inner list) items

if i click the another item of 1st ListBox what ever we open 2nd listBox is closed and open new one relative Listbox2 for that item .
Posted

 
Share this answer
 
Comments
venuchary 4-May-13 1:49am    
thanks , i have tried ur solution but it showing statically
see this link
http://1.bp.blogspot.com/-Fmj01D-wqaA/TgliPIZ1oaI/AAAAAAAAA1k/pzKwJdQDEcQ/s1600/device.png

when ever the click the tap of 1st listitem then only open the second list of particular item and if i click the another item in list 1 then closed 2nd list and open the for clicked one
Here is a sample... use this...hope it helps...
HTML
<listbox x:name="TeamListbox" horizontalalignment="Left" height="Auto" verticalalignment="Top" width="Auto" style="{StaticResource ListBoxStyle1}" itemtemplate="{StaticResource DataTemplate1}" xmlns:x="#unknown">               
</listbox>

The definitions for datatemplate is
HTML
<phone:phoneapplicationpage.resources xmlns:phone="#unknown">
               <datatemplate x:key="DataTemplate2" xmlns:x="#unknown">
		<grid>
                  <textblock margin="0,0,1,0" fontsize="25" foreground="Green" fontweight="SemiBold" textwrapping="Wrap" text="{Binding }" d:layoutoverrides="Width, Height" xmlns:d="#unknown" />
		</grid>
	      </datatemplate>
	      <datatemplate x:key="DataTemplate1" xmlns:x="#unknown">
                 <stackpanel>
                   <textblock margin="0,0,1,0" fontsize="32" foreground="White" fontweight="Bold" textwrapping="Wrap" text="{Binding TeamName}" d:layoutoverrides="Width, Height" tap="TextBlock_Tap" xmlns:d="#unknown" />
                  <listbox x:name="InnerLsitbox" tag="{Binding TeamName}" itemtemplate="{StaticResource DataTemplate2}" itemssource="{Binding TeamMembers}" visibility="Collapsed" />
                </stackpanel>
              </datatemplate>
</phone:phoneapplicationpage.resources>



In code-behind,
define your own class
C#
 public class Teams
    {
        public string TeamName { get; set; }
        public List<string> TeamMembers { get; set; }
    }
</string>



Initilalise the collection and fill with some dummy data
C#
ObservableCollection<teams> teams ;
        private FrameworkElement expandedElement;
        public MainPage()
        {
            InitializeComponent();
            teams = new ObservableCollection<teams>();
            InitializeTeams();
            TeamListbox.ItemsSource = teams;
        }

        public void InitializeTeams()
        {
            teams.Add(new Teams() { TeamName = "India", TeamMembers= new List<string>  () { "aaaaa1", "sssssssss1", "ddddd1", "fffffffffff1", "zzzzzzz1", "ccccc1" } });
            teams.Add(new Teams() { TeamName = "Australia", TeamMembers = new List<string>() { "aaaaa2", "sssssssss2", "ddddd2", "fffffffffff2", "zzzzzzz2", "ccccc2" } });
            teams.Add(new Teams() { TeamName = "Srilanka", TeamMembers = new List<string>() { "aaaaa3", "sssssssss3", "ddddd3", "fffffffffff3", "zzzzzzz3", "ccccc3" } });
            teams.Add(new Teams() { TeamName = "South Africa", TeamMembers = new List<string>() { "aaaaa4", "sssssssss4", "ddddd4", "fffffffffff4", "zzzzzzz4", "ccccc4" } });
            teams.Add(new Teams() { TeamName = "England", TeamMembers = new List<string>() { "aaaaa5", "sssssssss5", "ddddd5", "fffffffffff5", "zzzzzzz5", "ccccc5" } });
            teams.Add(new Teams() { TeamName = "West Indies", TeamMembers = new List<string>() { "aaaaa6", "sssssssss6", "ddddd6", "fffffffffff6", "zzzzzzz6", "ccccc6" } });
        }
</string></string></string></string></string></string></teams></teams>


In the tap event, handle the visibility of innerListbox like this
C#
private void TextBlock_Tap(object sender, GestureEventArgs e)
        {
            if (expandedElement != null)
                (expandedElement as ListBox).Visibility = System.Windows.Visibility.Collapsed;
            ListBox ll = (((sender as TextBlock).Parent as StackPanel).Children[1] as ListBox);
            expandedElement = ll;
            ll.Visibility = System.Windows.Visibility.Visible;
}
 
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