This project is read-only.

Having trouble GetFirstDescendantOfType on a GridView

Apr 7, 2014 at 4:46 AM
Edited Apr 7, 2014 at 4:48 AM
There are quite a few StackOverflow questions that explain how to fish the ScrollViewer out of a GridView using
Unfortunately, I'm not able to get it to work. Starting with a GridApp sample from Visual Studio, I add two lines to the GroupedItemsPage navigationHelper_LoadState method:
var scroller = this.itemGridView.GetFirstDescendantOfType<ScrollViewer>();
scroller.ViewChanged += scroller_ViewChanged;
Whenever I do this, scroller comes out as "null"

I noticed that none of the stackoverflow answers are that recent, so it's possible that the internal structure of a GridView has changed, and you can't fish out the ScrollViewer anymore.

I tried to build WinRtXamlToolkit from source so that I could step into the method and maybe see what's going wrong, but that failed with a lot of "Payload File . . . .xbf does not exist" errors

Does anybody know if I'm screwing up, or if there's some simpler explanation? I'm also open to suggestions on how to debug this myself.
Apr 7, 2014 at 7:16 AM
Are you waiting for the Loaded event before digging into the visual tree? If not - the control template is likely not yet loaded.
Marked as answer by pbaughman on 4/7/2014 at 9:37 AM
Apr 7, 2014 at 5:38 PM
Bingo - No luck when I tried to wire it up in the constructor, or when the page was navigated to. Putting it in the page loaded event has resolved the problem.