Question

I have a TextBox in Silverlight 5 where I am setting the Text value from Code. When the Textbox Visibility is Visible, it will fire off the TextChanged event, but as soon as you set it to Collapsed, it doesn't fire anymore.

Does anyone have experience with this? I found 1 site where someone has also experienced the issue but was never answered.

I'll implement a temp hack to manually fire if off but if I can't solve the problem I'll need to rework a large portion of code to use a different path completely.

Thanks

Was it helpful?

Solution

Events are not firing if the control's visibility is set to Collapsed. And there is not Hidden Visibility in Silverlight. But you can set Opacity=0 to make it hidden.You'll also want to set IsHitTestVisible to false on an element you've set Opacity=0 on, otherwise the user will still be able to click on it, even if they meant to click on some underlying element. The event will fire then.

<TextBox  TextChanged="textBox1_TextChanged" x:Name="txt" Opacity="0" IsHitTestVisible="False"/>

Or you must fire it explicitly.

OTHER TIPS

If I'm not mistaken, actually making IsHitTestVisible="False" implies the TextChanged event isn't fired either.

So Opacity="0" instead of Collapsed visibility is all that is needed (you can also make the TextBox a tiny size to further make sure it is never hit :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top