Search code examples
wpfvalidationvalidationrules

Using WPF Validation rules and the disabling of a 'Save' button


I have a page where a few textboxes cannot be empty before clicking a Save button.

<TextBox...

                <TextBox.Text>
                    <Binding Path ="LastName" UpdateSourceTrigger="PropertyChanged">

                        <Binding.ValidationRules>
                            <local:StringRequiredValidationRule />
                        </Binding.ValidationRules>                              
                    </Binding>
                </TextBox.Text>

My rule works, I have a red border around my textbox until I enter a value. I now want to add this validation rule to my other text boxes.

How do I disable the Save button until the page has no validation errors? I'm not sure what to check.


Solution

  • Here is the complete sample what you need.

    http://codeblitz.wordpress.com/2009/05/08/wpf-validation-made-easy-with-idataerrorinfo/

    https://skydrive.live.com/?cid=2c6600f1c1d5e3be&id=2C6600F1C1D5E3BE%21203

    enter image description here