views:

52

answers:

1

Hi !

I have a WPF UserControl with many other controls inside of it. TextBoxes are among these. Every TextBox has its own validation:

<TextBox>
    <TextBox.Text>
        <Binding Path="MyPath" StringFormat="{}{0:N}" NotifyOnValidationError="True">
            <Binding.ValidationRules>
                <r:MyValidationRule ValidationType="decimal" />
            </Binding.ValidationRules>
        </Binding>
    <TextBox.Text>
<TextBox>

a

Now suppose the user types some invalid characters into them. They will all become highlighted red.

Now I want to reset all the validation errors (from the incorrect input) and set the recent correct values coming from DataContext.

I set the DataContext in the constructor and I don't want to change it (DataContext = null won't help me then):

DataContext = _myDataContext = new MyDataContext(..);

What I've already found are these classes:

Validation.ClearInvalid(..)
BindingExpression.UpdateTarget();

I think these classes could help me, but they require the Binding of a concrete FrameworkElement and I want to do it globally for all of them.

Should I anyhow iterate through the Visual Tree (which is really what I don't like) or is there any better solution for this?

A: 

Why won't you just trigger NotifyPropertyChanged for all the properties of your data source? This will update binding and UI controls should get values from datacontext (which are valid, thus validation errors will be cleared)?

Andrii V
Nope.. I've tried this as first.. it didn't work :-/
PaN1C_Showt1Me
Oh, got it, it works for me because I use ValidatesOnExceptions option and throw validation exceptions in setters. So original (valid) values are not overriden with invalid.
Andrii V