Search code examples
c++-winrt

Trouble traversing Visual Tree in C++/WinRT


I'm implementing an app w/ Excel-style functionality where I have a ListBox of baskets, each containing a ListBox of Items, each containing a StackPanel-nested Button inside it.

XAML, What the layout looks like

Goal: I want to click on the button, such that the item entry (StackPanel) is highlighted via SelectedIndex(). I try to accomplish this in the GotFocus="ItemGotFocus" event handler, by traversing the visual tree to find the parent ListBox, so I can call SelectedIndex() on it.

However, I am getting errors whenever I call VisualTreeHelper::GetParent() or other functions from the namespapce in general:

Do I need to define a template definition somewhere, so it can figure out the type I want it to return, or is there a better way to go about this?


Solution

  • Thank you, it worked!

    Turns out I had included <winrt/Microsoft.UI.Xaml.Media.h> in "pch.h", when what I really needed was <winrt/Windows.UI.Xaml.Media.h>.