Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");
    }
}
like image 728
OneMoreVladimir Avatar asked Aug 18 '12 15:08

OneMoreVladimir


1 Answers

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}"/>
like image 144
Aghilas Yakoub Avatar answered Nov 10 '22 13:11

Aghilas Yakoub