04 February, 2014

Workaround for Visibility.Hidden in Silverlight

I love working on XAML/Silverlight and I don't face any issues most of the times. But when I am in trouble, I don't find any clue on how to come out of that. Recently, I am working on a Silverlight application and got a requirement to apply background color for Items which contains Collapsible Controls. To Understand this properly, I have a list of CheckBoxes with TextBox Controls and the TextBox should only be visible on CheckBox Check. To accomplish this, I simply Binded the Visibility of TextBox with IsChecked Property and thats working like charm.

The problem is when I apply BackgroundColor to those Items. If I apply a BackgroundColor to ListItem in Template, It is taking only till CheckBox content, if there is no TextBox (i.e., CheckBox is Unchecked).
Now I came to know the importance of Hidden in the Visibility Values. But soon I found that its not supported in Silverlight.
The only work around for this is to manipulate Opacity of the TextBox instead of Visibility. This fulfilled my requirement and hope works in all the situations. I haven't tested for TabStop, HitVisibility, ScreenReaders as they are out of scope in our project. The Final Binding will look like following: