Interface => IDataErrorInfo
Introduction to common Interfaces
IDataErrorInfo
Provides the functionality to offer custom error information that a user interface can bind to.
.NET Framework Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
.NET Framework Client Profile Supported in: 4, 3.5 SP1
Example 1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace IDataErrorProviderExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
//var person = new Person();
var person = new Person { Age = };
//var person = new Person { Age = 200 };
//ageTextBox.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnPropertyChanged, null, "No");
ageTextBox.DataBindings.Add("Text", person, "Age", true, DataSourceUpdateMode.OnPropertyChanged); //case 1
errorProvider1.DataSource = person; //case 2
//errorProvider1.SetError(ageTextBox, "==="); //temp
}
} public class Person : IDataErrorInfo
{
private int age; public int Age
{
get { return age; }
set { age = value; }
} public string Error
{
get
{
//check validation on every property
return "";
}
} public string this[string name]
{
get
{
string result = null; switch (name)
{
case "Age":
if (this.age < || this.age > )
{
result = "Age must not be less than 0 or greater than 150.";
}
break;
default:
break;
} return result;
}
}
}
}
Interface => IDataErrorInfo的更多相关文章
- ASP.NET MVC下的四种验证编程方式
ASP.NET MVC采用Model绑定为目标Action生成了相应的参数列表,但是在真正执行目标Action方法之前,还需要对绑定的参数实施验证以确保其有效性,我们将针对参数的验证成为Model绑定 ...
- Model的验证
ModelValidator与ModelValidatorProvider ModelValidator public abstract class ModelValidator { public v ...
- WPF Input Validation Using MVVM
Data validation is a key part in WPF.Validation is used to alert the user that the data he entered i ...
- angular2系列教程(七)Injectable、Promise、Interface、使用服务
今天我们要讲的ng2的service这个概念,和ng1一样,service通常用于发送http请求,但其实你可以在里面封装任何你想封装的方法,有时候控制器之间的通讯也是依靠service来完成的,让我 ...
- 接口--interface
“interface”(接口)关键字使抽象的概念更深入了一层.我们可将其想象为一个“纯”抽象类.它允许创建者规定一个类的基本形式:方法名.自变量列表以及返回类型,但不规定方法主体.接口也包含了基本数据 ...
- Configure a bridge interface over a VLAN tagged bonded interface
SOLUTION VERIFIED February 5 2014 KB340153 Environment Red Hat Enterprise Linux 6 (All Versions) Red ...
- Create a bridge using a tagged vlan (8021.q) interface
SOLUTION VERIFIED April 27 2013 KB26727 Environment Red Hat Enterprise Linux 5 Red Hat Enterprise Li ...
- Configure a bridged network interface for KVM using RHEL 5.4 or later?
environment Red Hat Enterprise Linux 5.4 or later Red Hat Enterprise Linux 6.0 or later KVM virtual ...
- Set up VLAN (802.1q) tagging on a network interface?
SOLUTION VERIFIED October 13 2015 KB39674 KB741413 environment Red Hat Enterprise Linux 4 Red Hat En ...
随机推荐
- 【转】ContextLoaderListener 和 DispatcherServlet
转载地址: http://www.guoweiwei.com/archives/797 DispatcherServlet介绍 DispatcherServlet是Spring前端控制器的实现,提供S ...
- 请将 php.ini 中的 short_open_tag 设置为 On,否则无法继续安装。
安装的wamp套件,访问http://localhost/Discuz/install/index.PHP进行安装操作,提示 对不起,请将 php.ini 中的 short_open_tag 设置为 ...
- window计划任务
我的电脑->管理->任务计划程序 [或:控制面板->类别:大图像->管理工具->任务计划程序] 右边创建任务: 常规:名字和 是否 只在用户登录是运行 触发器:新 ...
- [转]expect的安装
转自:http://blog.chinaunix.net/uid-20639775-id-2453085.html Expect是在Tcl基础上创建起来的,它还提供了一些Tcl所没有的命令,它可以用来 ...
- linux安装SVN
1. 下载软件包 http://archive.apache.org/dist/subversion/ http://archive.apache.org/dist/subversion/subver ...
- Oracle 时间,日期 类型函数及参数详解
ORACLE字符数字日期之间转化 Java代码 24 小时的形式显示出来要用 HH24 select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss' ...
- JAVA的自动装箱拆箱
转自:http://www.cnblogs.com/danne823/archive/2011/04/22/2025332.html 蛋呢 的空间 ??什么是自动装箱拆箱 基本数据类型的自动装箱(a ...
- 洛谷 P1803 凌乱的yyy Label:Water 贪心
题目背景 快noip了,yyy很紧张! 题目描述 现在各大oj上有n个比赛,每个比赛的开始.结束的时间点是知道的. yyy认为,参加越多的比赛,noip就能考的越好(假的) 所以,他想知道他最多能参加 ...
- YSLOW
什么是YSlow? YSlow是Yahoo发布的一款基于FireFox的插件. 如何安装YSlow? 安装YSlow必须首先先安装 Firebug,然后下载YSlow,再对其安装. YSlow有什么用 ...
- 使用ajax和history.pushState无刷新改变页面URL
表现 如果你使用chrome或者firefox等浏览器访问本博客.github.com.plus.google.com等网站时,细心的你会发现页面之间的点击是通过ajax异步请求的,同时页面的URL发 ...