Mark Carpenter
Mark Carpenter

Reputation: 17775

What's the best way to go about form validation in WPF (with databinding)?

I have several forms with many textboxes/comboboxes, and I would like to have the "Save" button disabled while at least one of the fields are invalid. I've been able to setup some custom ValidationRules, like so (textbox example shown):

<Binding Path="Name">
    <Binding.ValidationRules>
        <my:TextFieldNotEmpty/>
    </Binding.ValidationRules>
</Binding>

My question is: how can I set my form up so that, when even 1 validation rule fails, the "Save" button is not enabled? Is there a standard way of handling a situation (a trigger, perhaps), or is this a place where WPF falls short?

Upvotes: 1

Views: 3362

Answers (3)

jbe
jbe

Reputation: 7031

You might be interested in the BookLibrary sample application of the WPF Application Framework (WAF). It shows how to use validation in WPF and how to control the Save button when validation errors exists.

Upvotes: 1

Vegar
Vegar

Reputation: 12898

Will this answer your question? Detecting WPF Validation Errors

Upvotes: 1

Related Questions