使用 WPF 验证规则和禁用“保存"按钮 [英] Using WPF Validation rules and the disabling of a 'Save' button

查看:27
本文介绍了使用 WPF 验证规则和禁用“保存"按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,在单击保存"按钮之前,其中一些文本框不能为空.

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.

推荐答案

这里是您需要的完整示例.

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=2c6600f1c1d;5e3id=2C6600F1C1D5E3BE%21203

这篇关于使用 WPF 验证规则和禁用“保存"按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆