使用 Prism 进行 Silverlight 3 验证

发布于 2024-07-21 04:23:49 字数 214 浏览 5 评论 0原文

我正在使用 Prism 开发 SL3 应用程序。 我需要支持验证(字段级别(在绑定属性的设置器上)和保存之前(表单级别)),包括按下保存按钮时显示的验证摘要。

但我可以通过谷歌搜索找到的示例要么是 SL3,在代码后面有很多代码(非常不酷且非 Prismy),要么是 WPF 相关的。

有谁知道我可以研究一些实际验证的参考应用程序?

干杯, 阿里

I'm developing a SL3 application with Prism. I need to have support for validation (both field level (on the setter of the bound property) and before save (form level)), including a validation summary, shown when the save button is pressed.

But the samples I can find googling are either SL3 with a lot of code in code behind (very uncool and un-Prismy), or WPF related.

Does anyone know a reference application with some actual validation I can look into?

Cheers,
Ali

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捎一片雪花 2024-07-28 04:23:49

目前还没有来自 Microsoft 的任何信息,但明天我会将其传递给 PRISM 团队,看看我们是否可以在下一版本的 PRISM 中获得基本的表单验证示例。

话虽这么说,您可以为每个表单放置一个验证器,该验证器本质上验证每个字段(语义和/或语法验证),并且如果全部通过,将返回 true/false 状态。

我通常这样做的一种方法是将“CanSave”方法附加到我的命令中,即:

SaveOrderCommand = new DelegateCommand<object>(this.Save, this.CanSave);

private bool CanSave(object arg)
{
     return this.errors.Count == 0 && this.Quantity > 0;
}

然后在 this.CanSave 中,我将基本验证放入此代码库中,或者调用一堆其他验证器取决于上下文 - 有些将在所有模块之间共享(即 IsEmailValid 将是我作为单例放置在基础设施模块中的一个验证器并传入我的字符串,然后结果是 true/false)。 一旦全部通过,请确保 CanSave 返回 true。 如果失败,CanSave 将返回 False。

现在,如果它们失败了,并且您想向用户发出友好的提醒,表明其失败了,您可以在此处使用多种技术。 我通常在验证时将所述控件标记为“失败”..(我自己写的,所以你可以在这里使用哪些工具包 - http://www.codeplex.com/SilverlightValidator 是一个不错的)。

现在,我通常喜欢对经过验证的表单进行更多操作,不仅突出显示所述控件(红色框、图标等),而且还向用户更详细地解释它们的要求 - 因此自定义方法是我的解决方案已经选择了

归根结底,您将不得不做一些繁重的工作来验证您的特定表单 - 但要研究在有意义的地方重用验证器的方法(电子邮件、SSN 等很容易重新使用)使用)。

哈?

Scott Barnes - 丰富平台产品经理 - Microsoft。

There aren't any from Microsoft at present, but I'll pass this one onto the PRISM team tomorrow to see if we can get a basic Form Validation example inside the next rev of PRISM.

That being said, you can put a validator per Form that essentially validates each field (semantic and/or syntax validation) and should all pass, will return a true/false state.

A way I typically do this is I attach a "CanSave" method to my Commands ie:

SaveOrderCommand = new DelegateCommand<object>(this.Save, this.CanSave);

private bool CanSave(object arg)
{
     return this.errors.Count == 0 && this.Quantity > 0;
}

Then in the this.CanSave, i then put either the basic validation inside this codebase, or I call a bunch of other validators depending on the context - some would be shared across all modules (ie IsEmailValid would be one Validator i place in my Infrastructure Module as a singleton and pass in my string, it would then true/false as a result). Once they all pass, ensure CanSave returns true. If they fail, the CanSave will return False.

Now if they fail and you want to trigger a friendly reminder to the user that its failed theres a number of techniques you can use here. I've typically flagged the said control at validation as being "failed".. (i wrote my own mind you, so up to you which toolkits you could use here - http://www.codeplex.com/SilverlightValidator is a not bad one).

Now, I typically like to do more with Forms that have validation on them by not only highlighting the said control (red box, icon etc) but also explain to the user in more detail whats required of them - thus custom approach is a solution I've opted for.

At the end of the day, you're going to have to do some of the heavy lifting to validate your particular form - but look into ways to re-use validators where they make sense (email, SSN etc are easy ones to re-use).

HTH?

Scott Barnes - Rich Platforms Product Manager - Microsoft.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文