Textbox binding update in WPF [duplicate]
MessageText property gets updated only when I hit another control. What is more if I press any button it's Click handler isn't executed and the MessageText set is executed instead. I've broken my head.
<TextBox x:Name="messageText" Grid.Row="1" Grid.Column="0"
TextWrapping="Wrap" Text="{Binding Path=MessageText, Mode=TwoWay}"/>
private void ChatView_Loaded(object sender, RoutedEventArgs e)
{
DataContext = viewModel;
}
public string MessageText
{
get
{
return this.messageText;
}
set
{
this.messageText = value;
OnProperyChanged("MessageText");
}
}
You can adjust UpdateSourceTrigger to PropertyChanged
<TextBox x:Name="messageText" Grid.Row="1" Grid.Column="0"
TextWrapping="Wrap" Text="{Binding Path=MessageText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>