1

I am working on a Silverlight project, and recently someone on my team added var popups = VisualTreeHelper.GetOpenPopups() to a method in our app. When I got their code from source control I got a compile error saying that GetOpenPopups wasn't found on VisualTreeHelper. VisualTreeHelper is an object coming from the System.Windows.Media namespace, and there is no difference between my code file (for this file) and that of the rest of my team. In the object browser I can see that in the System.Windows assembly under the System.Windows.Media namespace, the GetOpenPopups method is not listed for me, but it is for the rest of my team. It appears that somehow we have different versions of these assemblies, but there are no warnings about reference versions being incorrect from the project/solution.

What am I missing here? Why is GetOpenPopups() missing for me (and not the rest of my team)?

Adam Jones
  • 711
  • 3
  • 9

3 Answers3

2

Are you sure that you're referencing the Silverlight version of the assembly? The standard .Net version does not include the method, whereas the SL one does.

dlev
  • 48,024
  • 5
  • 125
  • 132
  • Yes, I am using the Silverlight version. It is referenced in the Silverlight project and it won't let you add a reference to a non-Silverlight assembly. – Adam Jones Aug 11 '11 at 18:22
  • Hmm... Are you developing a Winphone7 application then? – dlev Aug 11 '11 at 18:23
1

On a hunch I downloaded and installed the most recent version of the Silverlight SDK (no code change within the project), and now the method is showing up on VisualTreeHelper. Aparently GetOpenPopups is a recently added method (as of Silverlight 4). I thought I had installed the SDK before, and we have been developing against Silverlight 4 since the start of our project about a year ago, so I am still confused as to why it wasn't available on my machine. There were no warnings or errors about versions being different from what was available on my machine and what was referenced in our project. Looks like I might need to read up on versioning in .NET assemblies to better understand how it works and to make sure this won't be an issue at deployment. Thanks for the suggestions guys.

Adam Jones
  • 711
  • 3
  • 9
0

Silverlight has a very limited set of members on its VisualTreeHelper and GetOpenPopups is not one of them. The question really is why is the rest of your team seeing a method that doesn't exist?

One scenario might be that the code file is linked in another project WPF project but someone has forgotten to protect this chunk of code with a #if SILVERLIGHT. Looks fine for them because their working on a WPF project currently.

A lesson here is to check the online MSDN docs first or just plain try it before answering.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Hey Anthony, ran across your blog post [The Coding Bloke - Visual Tree Enumeration](http://geekswithblogs.net/codingbloke/archive/2010/12/19/visual-tree-enumeration.aspx) recently and bookmarked it. I actually referred the article to someone earlier today who was working with cells in a datagrid. Thanks for your suggestion, but it turns out that it was a version problem. MSDN says `GetOpenPopups` is new as of Silverlight 4 (which we have been using for over a year, but for some reason I must have had an old assembly). We do have some shared WPF code, but this wasn't part of it. – Adam Jones Aug 12 '11 at 05:46
  • @Adam: Thats very interesting, I tend to use .chm files for documentation access, I find its much more responsive. You're absolutely right GetOpenPopups is present, its just no documented in the .chm file. May be I should go looking for an updated .chm file. – AnthonyWJones Aug 12 '11 at 08:18