2
votes

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="copyrightsTextBox"
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.

1

1 Answers

3
votes

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();
    }