最后,我找到了一个解决方案,而不会过多地破坏我使用的 MVVM 模式(指的是具有特定名称的特定控件)。
我所做的是设置UpdateSourceTrigger为PropertyChanged而不是LostFocus. 问题PropertyChanged是我ValueConverter的不再运行了。因此,尽管按钮现在可以正确启用或禁用,并且准时准备好接收焦点,但我的文本框中显示的值并不正确。
我通过收听文本框的LostFocus事件解决了这个问题,并且现在正确地使用BindingExpression.UpdateTarget()了我的显示。TextBox.Text
这里是:
<TextBox
Text="{Binding Path=SpecialText, Converter={StaticResource myConverter}, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
LostFocus="TextBox_LostFocus">
</TextBox>
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
{
(sender as TextBox).GetBindingExpression(TextBox.TextProperty).UpdateTarget();
}