views:

171

answers:

2

Hi,

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

A: 

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);
Jeff Wain
That won't work, because the GridView object is not a visual child of the ListView...
Thomas Levesque
So you don't have the GridView declared in code? Even if it's part of a template, you should still be able to find it through the visual tree. See this post for a method of declaring it that you could use. http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/ed4ab24e-28b0-49f2-986d-38bdae10051d
Jeff Wain
As I said, it is not in the visual tree. The GridView isn't even a `Visual`, it's just a kind of "descriptor" that provides a style for the view, and a method to prepare items for display. On the other hand, I would have expected it to be in the logical tree...
Thomas Levesque
A: 

This seems to be impossible?

J W