Windows 8 Metro:实施验证 [英] Windows 8 Metro: Implementing Validation

查看:23
本文介绍了Windows 8 Metro:实施验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是用谷歌搜索了大约 2 个小时,但没有找到任何东西.

鉴于以下场景:

公共类人{[必需的]公共字符串名称{获取;放;}}

XAML:

您将如何像在 MVC3 中那样在 UI 上自动获取验证的反馈?

(哦,我现在真的不在乎我是否能够使用像 [Required] 这样的集成 DataAnnotations)

非常感谢任何帮助!

解决方案

我在 WinRT XAML 工具包中添加了一些内容

一>.它被称为 TextBoxValidationExtensions 并允许您像这样定义验证:

格式目前定义为:

[标志]公共枚举 ValidTextBoxFormats{任意 = 0,非空 = 1,数字 = 2,非空数字 = 3}

整个代码有点长,无法在这里分享.您可以从 CodePlex 中取出代码并根据自己的喜好进行修改 - 添加新的验证规则、修改默认画笔等.

I just googled for about 2 hours and didn't find anything.

Given the following scenario:

public class Person
{
    [Required]
    public string Name { get; set; }
}

XAML:

<TextBox Text="{Binding Name, Mode=TwoWay}" />

How would you go about automatically get feedback of the validation on the UI like there is in MVC3?

(Oh, and I really don't care at the moment if I would be able to use the integrated DataAnnotations like [Required] or not)

Any help is much appreciated!

解决方案

I added something to the WinRT XAML Toolkit. It's called TextBoxValidationExtensions and allows you to define the validation like this:

<TextBox
    Width="400"
    HorizontalAlignment="Left"
    xyzc:TextBoxValidationExtensions.Format="NonEmptyNumeric"
    xyzc:TextBoxValidationExtensions.InvalidBrush="Red"
    xyzc:TextBoxValidationExtensions.ValidBrush="Green" />

The formats are currently defined as:

[Flags]
public enum ValidTextBoxFormats
{
    Any = 0,
    NonEmpty = 1,
    Numeric = 2,
    NonEmptyNumeric = 3
}

The entire code is a bit too long to share here. You can take out the code from CodePlex and modify to your liking - add new validation rules, modify default brushes etc.

这篇关于Windows 8 Metro:实施验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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