Monday, December 1, 2008

Help! I Can't Access Anything Inside My Silverlight Viewbox!

The much anticipated Viewbox control is finally here. I have been waiting patiently for this control for a while now. It behaves the same way the Viewbox in WPF does. It takes its content and allows it to stretch and contract to fill the desired space... Very handy!

One small issue... a bug. As of the latest release (11/29/08), you cannot directly access any object you place inside the Viewbox. For example, you can have a viewbox that contains a Button named myButton.

<controls:Viewbox x:Name="vBox">
Button x:Name="myButton"/>

In your code behind, if you try to access myButton, it will always return null. This is a known issue that the Silverlight team working on the toolkit has promised to fix. For now, here is the workaround. Simply access myButton by looking at the Child property of the Viewbox.

((Button)vBox.Child).Text = "myButton Text";

No comments:

Post a Comment