Answered by:
Winrt VisualTreeHelper on GridView

Question
-
When I use the visual tree helper to get the children items of a GridView the GridViewItemPresenter only has one child which is the first item in the grid view content. The other items are not retrieved. Any Idea why only the first item in the GridView is retrieved?
public static IEnumerable<DependencyObject> GetChildren(this DependencyObject obj)//obj is GridViewItemPresenter { var count = VisualTreeHelper.GetChildrenCount(obj);//Count is only 1 but GridView has 4 children?? for (int i = 0; i < count; i++) { var child = VisualTreeHelper.GetChild(obj, i); yield return child; } }
Monday, November 25, 2013 11:16 PM
Answers
-
GridViewItemPresenter presents one gridviewitem. it isnt the ItemsPanel. it the template of the GridViewItem
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Marked as answer by Jamles HezModerator Friday, December 13, 2013 8:14 AM
Tuesday, November 26, 2013 9:55 AM
All replies
-
Hi ,
Without being 100 % sure perhaps it has to do with the fact that the other children are not loaded yet.
In my case I had a flipview with 7 flipviewitems and inside some grids.
When the XAML page appears only the 3 of them are filled .
That is why I would suggest to run your code in the loaded event of the page or if the gridview has a loaded event to run your code in there.
For example the list view has a LayoutUpdated where in the ONNavigatedto event I'm doing the below
this.itemNumbersListView.LayoutUpdated += itemNumbersListView_LayoutUpdated;
void itemNumbersListView_LayoutUpdated(object sender, object e)
{
this.itemNumbersListView.LayoutUpdated -= itemNumbersListView_LayoutUpdated;
//write your loop
}Perhaps you might want to try the above.
thank you
Tuesday, November 26, 2013 8:37 AM -
GridViewItemPresenter presents one gridviewitem. it isnt the ItemsPanel. it the template of the GridViewItem
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Marked as answer by Jamles HezModerator Friday, December 13, 2013 8:14 AM
Tuesday, November 26, 2013 9:55 AM -
Good Point. I will check that out.Monday, December 2, 2013 10:21 PM
-
I am running my code from the Page Loaded event.Monday, December 2, 2013 10:22 PM