As in Windows Phone 7 we generaly display lists of Data in the ListBox. So many times we came across the problem of retrieving the controls inside the ListBox itemTemplate. As we can take the example of buttons inside the ListBoxItem and on those Button click we can view the RowDetails.As in Windows Phone 7 ListBox does not support the RowDetailsVisibilityModeProperty so we have to put the Button inside the ListBoxItemTemplate and on the click event of that we have to make the visibility of the TextBlock collapse or visible.
Following are the steps
*First create a new Project named it as UserDetails * Add a new Item named it as Details.xaml
* Add the Following code in the Details.xaml
*First create a new Project named it as UserDetails * Add a new Item named it as Details.xaml * Add the Following code in the Details.xaml
*Add the Following code to the Details.xaml.cs
namespace UserDetails { public partial class Details : PhoneApplicationPage { public Details() { InitializeComponent(); //creating the service client DetailsServiceReference.Service1Client DetailsClient = new DetailsServiceReference.Service1Client(); //Event handeler after web service complets operation DetailsClient.UserDetailsCompleted += new EventHandler (DetailsClient_UserDetailsCompleted); //passing Selected SignID and Today's Date DetailsClient.UserDetailsAsync(); } /// /// Completed event of the UserDetails Details /// /// /// void DetailsClient_UserDetailsCompleted(object sender,DetailsServiceReference.UserDetailsCompletedEventArgs e) { try { List lsduserDetails = new List(); User user = new User(); user.OverView = e.Result.Overview; user.Extended = e.Result.Extended; user.LoveSingle = e.Result.UserInfo; user.LoveCouple = e.Result.UserDetails; lsduserDetails.Add(user); UserDetailsListBox.ItemsSource = lsduserDetails; } catch (Exception) { } } /// /// this method is responsible for retriving the listbox item /// /// /// /// private void GetChildren(UIElement parent, Type targetType, ref List children) { int count = VisualTreeHelper.GetChildrenCount(parent); if (count > 0) { for (int i = 0; i < count; i++) { UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i); if (child.GetType() == targetType) { children.Add(child); } GetChildren(child, targetType, ref children); } } } /// /// Tap event of the OverView ListBox item /// /// /// private void ImageOverViewOPen_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgOverVwOpen = (Image)children[0]; Image imgOverVwClose = (Image)children[1]; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockOverView = (TextBlock)children[1]; imgOverVwOpen .Visibility = Visibility.Collapsed; imgOverVwClose.Visibility = Visibility.Visible; blockOverView.Visibility = Visibility.Visible; } } /// /// Tap event of the close overVIew ListBOx item /// /// /// private void ImageOverViewClose_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgOverVwOpen = (Image)children[0]; Image imgOverVwClose = (Image)children[1]; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockOverView = (TextBlock)children[1]; imgOverVwClose.Visibility = Visibility.Collapsed; imgOverVwOpen.Visibility = Visibility.Visible; blockOverView.Visibility = Visibility.Collapsed; } } /// /// Tap event of the open Extended ListBox item /// /// /// private void ImageExtendedOPen_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgExtenOpen = (Image)children[2]; Image imgExtenClose = (Image)children[3]; Image imgOverVwOpen = (Image)children[0]; Image imgOverVwClose = (Image)children[1]; imgOverVwOpen.Visibility = Visibility.Visible; imgOverVwClose.Visibility = Visibility.Collapsed; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockExtended = (TextBlock)children[3]; imgExtenOpen.Visibility = Visibility.Collapsed; imgExtenClose.Visibility = Visibility.Visible; blockExtended.Visibility = Visibility.Visible; TextBlock blockOverView = (TextBlock)children[1]; blockOverView.Visibility = Visibility.Collapsed; } } /// /// Tap event of the close Extended ListBox item /// /// /// private void ImageExtendedClose_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgExtenOpen = (Image)children[2]; Image imgExtenClose = (Image)children[3]; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockExtended = (TextBlock)children[3]; blockExtended.Visibility = Visibility.Collapsed; imgExtenOpen.Visibility = Visibility.Visible; imgExtenClose.Visibility = Visibility.Collapsed; } } /// /// Tap event of the open LoveSingle ListBox item /// /// /// private void ImageUserInfOPen_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgUserInfoOpen = (Image)children[4]; Image imgUserInfoClose = (Image)children[5]; Image imgOverVwOpen = (Image)children[0]; Image imgOverVwClose = (Image)children[1]; imgOverVwOpen .Visibility = Visibility.Visible; imgOverVwClose .Visibility = Visibility.Collapsed; Image imgExtenOpen = (Image)children[2]; Image imgExtenClose = (Image)children[3]; imgExtenOpen.Visibility = Visibility.Visible; imgExtenClose.Visibility = Visibility.Collapsed; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockLoveSingle = (TextBlock)children[5]; imgUserInfoOpen.Visibility = Visibility.Collapsed; imgUserInfoClose .Visibility = Visibility.Visible; blockLoveSingle.Visibility = Visibility.Visible; TextBlock blockOverView = (TextBlock)children[1]; blockOverView.Visibility = Visibility.Collapsed; TextBlock blockExtended = (TextBlock)children[3]; blockExtended.Visibility = Visibility.Collapsed; } } /// /// Tap event of the close Lovesingle ListBox item /// /// /// private void ImageUserInfClose_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgUserInfoOpen = (Image)children[4]; Image imgUserInfoClose = (Image)children[5]; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockLoveSingle = (TextBlock)children[5]; imgUserInfoOpen .Visibility = Visibility.Collapsed; imgUserInfoClose .Visibility = Visibility.Visible; imgUserInfoOpen.Visibility = Visibility.Collapsed; } } /// /// tap event of the open Love couple listbox item /// /// /// private void ImageUserDetailsOPen_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgUserDetailsOPen = (Image)children[6]; Image imgUserDetailsClose = (Image)children[7]; Image imgOverVwOpen = (Image)children[0]; Image imgOverVwClose = (Image)children[1]; imgOverVwOpen.Visibility = Visibility.Visible; imgOverVwClose.Visibility = Visibility.Collapsed; Image imgUserInfoOpen = (Image)children[4]; Image imgUserInfoClose = (Image)children[5]; Image imgExtenOpen = (Image)children[2]; Image imgExtenClose = (Image)children[3]; imgExtenOpen .Visibility = Visibility.Visible; imgExtenClose.Visibility = Visibility.Collapsed; imgUserInfoOpen .Visibility = Visibility.Visible; imgUserInfoClose.Visibility = Visibility.Collapsed; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockLoveCouple = (TextBlock)children[7]; imgUserDetailsOPen.Visibility = Visibility.Collapsed; imgUserDetailsClose.Visibility = Visibility.Visible; blockLoveCouple.Visibility = Visibility.Visible; TextBlock blockLoveSingle = (TextBlock)children[5]; imgUserInfoOpen.Visibility = Visibility.Collapsed; imgUserInfoClose.Visibility = Visibility.Visible; blockLoveSingle.Visibility = Visibility.Collapsed; TextBlock blockOverView = (TextBlock)children[1]; blockOverView.Visibility = Visibility.Collapsed; TextBlock blockExtended = (TextBlock)children[3]; blockExtended.Visibility = Visibility.Collapsed; } } /// /// tap event of the close Love couple listbox item /// /// /// private void ImageUserDetailsClose_Tap(object sender, System.Windows.Input.GestureEventArgs e) { List items = new List(); GetChildren(UserDetailsListBox, typeof(ListBoxItem), ref items); foreach (ListBoxItem item in items) { List children = new List(); GetChildren(item, typeof(Image), ref children); Image imgUserDetailsOPen = (Image)children[6]; Image imgUserDetailsClose = (Image)children[7]; children.Clear(); GetChildren(item, typeof(TextBlock), ref children); TextBlock blockLoveCouple = (TextBlock)children[7]; imgUserDetailsClose.Visibility = Visibility.Collapsed; imgUserDetailsClose.Visibility = Visibility.Visible; blockLoveCouple.Visibility = Visibility.Collapsed; } } } /// /// User Details class property /// public class UserDetails { public string OverView { get; set; } public string Extended { get; set; } public string UserInfo { get; set; } public string UserDetails { get; set; } } }