I’m putting together some samples for an article for my Data Points column in MSDN Magazine on writing a line of business application with Silverlight communicating with WCF, and I ran into a few issues I did not expect. The one that really confused me causes the TextBox controls in the Silverlight application to:

    • not show the cursor in the TextBox (although I can type)
    • not show the contents being selected in the TextBox
    • breaks the TwoWay binding mode

I was living with the first 2 because I thought, eh, what the heck, its beta and I obviously hit some weird occurrence. But when the binding only worked one way from the source to the target TextBox controls, I knew I had a real problem. The TextBox controls when bound with Mode=TwoWay were not updating the source when I typed in the TextBox controls (and lost focus of course).

After a few posts in the Silverlight forums and some emails with some fellows at Microsoft, it was confirmed that there is a bug in the Silverlight 2 Beta 2 that causes the TextBox to not behave properly. The confusing aspect is trying to reproduce the problem. So I created a simple Silverlight user control, shown below:

<UserControl x:Class="TextBoxTester.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox x:Name="tbMsg" Text="Hello World" Height="30" Width="Auto"></TextBox>
    </Grid> 
</UserControl>

 

When this control is run from Visual Studio, there is no problem … nor is there a problem if I browse to the html page that hosts the compiled Silverlight application. WTF, says I! But if I browse to the html page that hosts the app, then REFRESH the page in the browser forcing the Silverlight control to reload the TextBox starts behaving badly. I tried this several times and it always reproduced it. However there are people I gave this same code to who saw the same behavior and others who did not. So there is obviously some other force intervening in this that I am not aware of still.

There are no error messages, no informational messages, nothing at all except a misbehaving TextBox control.

Anyway, I have been told that there is a bug regarding the TextBox control and that it will be fixed in a future release (prior to RTM of course). The causing factors are not completely known to me, but in case you run across this I figured I would shed a little light on it. The way I get around it for now is to click in the address bar of the browser, then click back on the Silverlight control. This seems to put the TextBox’s world back in order.