When binding the Text property on a TextBox to a property on a view model, the view model property doesn't get set until the TextBox is unfocused.
Steps to reproduce the behavior:
<TextBox Text="{x:Bind ViewModel.TheStringProperty, Mode=TwoWay}"/>
ViewModel.TheStringPropertyIf I were to bind something to ViewModel.TheStringProperty, it should behave exactly the same as if I had bound directly to the TextBox's Text property. (That is, ViewModel.TheStringProperty should be set as soon as the text changes.)
If applicable, add screenshots to help explain your problem.
NuGet Package(s):
Microsoft.Toolkit.Mvvm
Package Version(s):
Preview 4
Windows 10 Build Number:
App min and target version:
Device form factor:
Visual Studio
Hello yoshiask, thank you for opening an issue with us!
I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 馃檶
@yoshiask this is the default behavior of XAML unrelated to the toolkit. See the note in the docs:
By default, changes to TextBox.Text are sent to a two-way bound source when the TextBox loses focus. To cause changes to be sent after every user keystroke, set UpdateSourceTrigger to PropertyChanged on the binding in markup.
@Sergio0694 is there an example of this in the sample app for the MVVM Toolkit?
@michael-hawker Yup, we're using UpdateSourceTrigger=PropertyChanged in the interactive sample for the very first SetProperty example, with the binding to a TextBox 馃檪
@yoshiask That's in the ObservableObject sample page, should help as a reference and to see that in action!
@yoshiask you good with us closing this issue?
The reason I opened the issue is because this behavior is actually different than what I get when binding directly to the property in code behind. Maybe this is a bug with XAML then?
@yoshiask can you expand on what you mean by "binding directly to the property in code behind"? Are you talking about creating a Binding object manually or something else?
This is the expected behavior though for a TextBox, as per the docs.
This is the by design behavior through for a TextBox. Referring the Doc: https://docs.microsoft.com/en-us/windows/uwp/data-binding/data-binding-in-depth#binding-object-declared-using-binding
I dont think this is a bug for XAML
@yoshiask you good with us closing this issue?
Going to close the issue as this is the default behavior.
Most helpful comment
This is the by design behavior through for a TextBox. Referring the Doc: https://docs.microsoft.com/en-us/windows/uwp/data-binding/data-binding-in-depth#binding-object-declared-using-binding
I dont think this is a bug for XAML