Use different UpdateSourceTriggers for validation and convertion
I'm having a WPF TextBox which is bound to a (non-dependency) property of an object (implementing INotifyPropertyChanged to support binding).
<TextBox x:Name="copyrightsT开发者_开发知识库extBox"
Text="{Binding Path=Copyright, Mode=TwoWay, Converter={StaticResource CopyrightFormattingConverter}, ValidatesOnDataErrors=True}"/>
Validation is done by implementing IDataErrorInfo on the bound object.
I'd like to validate on PropertyChanged, but only convert on LostFocus. How can this be done (since only one UpdateSource trigger can be specified).
Any advise is welcome! Thanks in advance.
PropertyChanged
for text would occur if the text is changed, so you can handle the TextChanged
event and validate there manually.
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
(sender as TextBox).GetBindingExpression(TextBox.TextProperty).ValidateWithoutUpdate();
}
精彩评论