I have found that in a very specific situation, changing text in a TextBox does not update the underlying datasource when using data binding. If you set a property to either null or String.Empty twice in a row, then you enter a 1 character value in the
text box, the binding does not fire. Below is the code to reproduce.
In this code if have a "Person" class which stores a first and last name. I have implemented the INotifyPropertyChanged interface and made the FirstName and LastName properties bindable. I have put FirstName and LastName textboxes on my Silverlight form
and bound those textboxes to an instance of the class. On this form I have a button which sets the two properties to null and another that sets the two properties to String.Empty. There is also a multi-line textbox which displays a message any time the FirstName
property is set. This fires normally if you change the first name (and tab) or click one of the two buttons.
Here is how to reproduce the issue. Run the app, then click the "Set Null" button one time. Change the text of the First Name text box to a single character and press tab. You'll see that the change message properly fires. Now click the "Set Null" button
twice in a row, then change the First Name text box to a single character and press tab. This time the change message won't fire.
It will fire properly if you enter text that is more than one character long. You can also get the error to reproduce if you set the property to String.Empty twice in a row (or null then empty or empty then null). This issue appeared after upgrading to
RC0.
This will be a real issue for my application. I am writing a data entry application where the user can scroll through records and update data. For example, if the user is scrolling through names and two people in a row don't have middle initials, then
on the third name the user enters a one character initial, then the data won't be saved properly.
nelson5000
0 Points
4 Posts
DataBinding Bug - TextBox change does not update binding
Oct 09, 2008 07:04 PM | LINK
I have found that in a very specific situation, changing text in a TextBox does not update the underlying datasource when using data binding. If you set a property to either null or String.Empty twice in a row, then you enter a 1 character value in the text box, the binding does not fire. Below is the code to reproduce.
In this code if have a "Person" class which stores a first and last name. I have implemented the INotifyPropertyChanged interface and made the FirstName and LastName properties bindable. I have put FirstName and LastName textboxes on my Silverlight form and bound those textboxes to an instance of the class. On this form I have a button which sets the two properties to null and another that sets the two properties to String.Empty. There is also a multi-line textbox which displays a message any time the FirstName property is set. This fires normally if you change the first name (and tab) or click one of the two buttons.
Here is how to reproduce the issue. Run the app, then click the "Set Null" button one time. Change the text of the First Name text box to a single character and press tab. You'll see that the change message properly fires. Now click the "Set Null" button twice in a row, then change the First Name text box to a single character and press tab. This time the change message won't fire.
It will fire properly if you enter text that is more than one character long. You can also get the error to reproduce if you set the property to String.Empty twice in a row (or null then empty or empty then null). This issue appeared after upgrading to RC0.
This will be a real issue for my application. I am writing a data entry application where the user can scroll through records and update data. For example, if the user is scrolling through names and two people in a row don't have middle initials, then on the third name the user enters a one character initial, then the data won't be saved properly.
XAML:<
UserControl x:Class="BindIssue.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="400" Height="300"> <Canvas x:Name="LayoutRoot" Background="BlanchedAlmond"> <TextBlock x:Name="lblFirst" Canvas.Left="0" Canvas.Top="0" Text="First"></TextBlock> <TextBlock x:Name="lblLast" Canvas.Left="150" Canvas.Top="0" Text="Last"></TextBlock> <TextBox x:Name="tbFirst" Canvas.Left="0" Canvas.Top="20" Width="140"></TextBox> <TextBox x:Name="tbLast" Canvas.Left="150" Canvas.Top="20" Width="140"></TextBox> <Button x:Name="btnSetNull" Canvas.Left="0" Canvas.Top="50" Width="100" Height="30" Content="Set Null" Click="btnSetNull_Click"></Button> <Button x:Name="btnSetEmpty" Canvas.Left="150" Canvas.Top="50" Width="100" Height="30" Content="Set Empty" Click="btnSetEmpty_Click"></Button> <TextBlock x:Name="lblMessage" Canvas.Left="0" Canvas.Top="90" Text="Messages"></TextBlock> <TextBox x:Name="tbMessage" Canvas.Left="0" Canvas.Top="110" Width="400" Height="160"></TextBox> </Canvas></
UserControl>Code: