I am using Silverlight & MVVM pattern.
<TextBox Name="UserNameText" Text="{Binding Path=Username, Mode=TwoWay}" HorizontalContentAlignment="Stretch"/>
In this I had bound TextBox to a property Username and when Enter key is pressed and I am executing the LoginCommand in View Model.
private void LayoutRoot_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
this._viewModel.LoginCommand.Execute(null);
}
}
When username is entered in TextBox and ENTER key is pressed from the UserName TextBox, the LoginCommand is called, but the value is not updated in propery Username. It still contains null.
The values are bound if only there is a focus lost. How to fix this?
Change
UpdateSourceTrigger=PropertyChangedin the Binding. By default, the TextBox only updates it’s bound value onLostFocus. Setting it toPropertyChangedwill make it so it updates the bound value anytime the property changes.