Update text field binding in WPF

The MessageText property is only updated when I click on another control. Moreover, if I press any button, then this Click handler is not executed and the MessageText set is executed instead. I broke 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"); } } 
+43
c # data-binding wpf xaml
Aug 18 2018-12-18T00:
source share
1 answer

You can set UpdateSourceTrigger to PropertyChanged

 <TextBox x:Name="messageText" Grid.Row="1" Grid.Column="0" TextWrapping="Wrap" Text="{Binding Path=MessageText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> 
+104
Aug 18 2018-12-18T00:
source share



All Articles