Using the VisualTree in Silverlight

So I’m Very new to Silverlight and part of me likes it and the other part is just really confused… all the time.

Today I ran into a problem where I was working with a navigational frame with a ChildWindow and I needed the frame to be able to control elements and objects of the parent frame.
I racked my brain for close to 6 hours trying to find an answer to this question and I stumbled across something called LinqToVisualTree ( this allows me to tap into the Linq namespace and easily reference objects from other classes.
To be able to use it you will first need to be sure to add:

to the C# backend you will be working with.
Next make sure you copy over the class found on the link posted above and put it in a file (I named mine LinqToVisualTree.cs Go Figure). You don’t have to use the Namespace he has set up if you have a project-wide namespace you’re using you can add it to that namespace just make sure to change the locations mentioned.
Now for the code where we actually can reference our parent classes.. these are two different methods I found, both seemed to give me the same result:
Now in these examples you just need to change out the ChildWindow with the name of the parent class you will want to be working with.
From there you reference your parent class by doing something similar to this:
For example in the application I ended up using this in I did this:
A simple function that is run on a Selection change of a List Box I have in my main page. It will make the tab named detailsTab visible and then navigate you to it.
Tagged: ,


No comments yet, be the first.

Add a Comment