Visual Trees in Silverlight

One of my Silverlight applications failed to work with the current Google Chrome developer channel. An ItemsControl’s visual tree did not yet reflect the template when my code first accessed the visual tree. A Silverlight SDK blog entry discusses the timing of visual tree creation, and states that the visual tree is available immediately after ApplyTemplate is invoked. That wasn’t the case in this instance.

I found that it is more reliable to use the LayoutUpdated event handler to access the visual tree, as it is the last step of control creation. The event may also be raised earlier, so the handler needs to check that the visual tree is in the desired state. The visual tree will be ready prior to some invocation of the event handler.

The Silverlight application in question is now compatible with the Google developer channel.

Leave a Reply

You must be logged in to post a comment.