仅当我点击另一个控件时,才会更新MessageText属性。更重要的是,如果我按下任何按钮,它的Click处理程序不会执行,而是执行MessageText集。我已经坏了头。
<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");
}
}
答案 0 :(得分:126)
您可以将UpdateSourceTrigger调整为PropertyChanged
<TextBox x:Name="messageText" Grid.Row="1" Grid.Column="0"
TextWrapping="Wrap" Text="{Binding Path=MessageText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>