Migrating Silverlight TextBox to Version 2 RC0 |
Like many other folks in these days we also had to migrate our Silverlight code from Version 2 Beta 2 to Version 2 RC0. Fortunately almost none of the API changes affected our code, except an undocumented change to the predefined user control TextBox. We used to trigger the MouseLeftButtonDown event successfully until RC0. After the RC0 update the event didn’t fire and no error was thrown.
Additionally the TextBox was somehow locked whenever its visibility attribute was set collapsed and visible again: the user could not change the text within the TextBox any longer.
Here is our workaround:
- Replace the MouseLeftButtonDown event by a GotFocus event.
- Remove the TextBox from the children collection of its parent element and add it again.
The old code:
XAML:
<TextBox
x:Name="MessageTextBox" Text="(attach a message)"
MouseLeftButtonDown="MessageTextBox_MouseLeftButtonDown"
Height="80" Width="280" FontSize="14" Cursor="IBeam"
AcceptsReturn="True" VerticalScrollBarVisibility="Auto"
Style="{StaticResource TextBoxMessage}"/>
The new code:
XAML:
<TextBox
x:Name="MessageTextBox" Text="(attach a message)"
GotFocus="MessageTextBox_GotFocus"
Height="80" Width="280" FontSize="14" Cursor="IBeam"
AcceptsReturn="True" VerticalScrollBarVisibility="Auto"
Style="{StaticResource TextBoxMessage}"/>
C#:
ConfirmationDialog.Children.Remove(MessageTextBox); ConfirmationDialog.Children.Add(MessageTextBox);
