从gridview对象获取父级listview

问题描述:

在WPF应用程序的代码背后,我有一个包含GridView的变量.我肯定知道这个GridView是ListView的视图.有没有办法获得对该ListView的引用?

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?

谢谢

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);