问题
In the code-behind of a WPF application I have a variable containing a GridView. I know for sure that this GridView is the View of a ListView. Is there any way to get a reference to that ListView?
Thanks
回答1:
http://www.hardcodet.net/2008/02/find-wpf-parent
We've been using these helper classes for a while to find visual elements in the visual tree. In this case, you'd just want to use the method and it will hunt down the visual ancestor.
TryFindParent<ListView>(yourGridView);
来源:https://stackoverflow.com/questions/1420742/get-the-parent-listview-from-a-gridview-object