Thursday, June 18, 2009

Silverlight 2 TextBlock disappeared after being set to invisible

If you find your Silverlight TextBlock disappear after you set it to invisible. You may want to check its opacity property.

The case was to make TextBlock control visible and collapse based on certain condition. For some strange reason the TextBlock didn’t appear after I set the visibility back to visible. As I was using MVVM (Model View View Model) pattern, the TextBlock’s visibility was bound to view model object visibility property. I checked the control visibility property, it showed visible. Then I found the opacity was zero, I didn’t set the opacity to zero, but I guess when I dynamically attach the textbox to the parent with opacity 0, for some reason it follows previous opacity value of parent. Even tough, the parent already has opacity value of 1.0.

Yeap once again on cutting edge. So, if you find same situation Silverlight 2 TextBlock dissapearing, You may want to check its opacity.

No comments: