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 ...
随机推荐
- 指针与const
指向常量的指针,不能用于改变其所指对象的值. 指针的类型必须与所指对象的类型一致,但是有两个例外,第一种是允许令一个指向常量的指针指向一个非常量对象: double dra1 = 3.14; cons ...
- Monkeyrunner脚本中component快速定位方法
在编写MonkeyRunner脚本过程中,会出现component这一项内容,很多人可能不知道怎么确认,其实这个主要是为了指定要测试的程序包名和主Activity名,我们可以用以下方法去进行确认: 1 ...
- Wordpress如何开启用户注册功能
登录你的Wordpress管理员帐号,并进入管理后台,点击左侧菜单栏的"设置"--"常规" 在打开的设置页面,下方找到"允许任何人注册" ...
- URAL1018 Binary Apple Tree(树形DP)
题目大概说一棵n结点二叉苹果树,n-1个分支,每个分支各有苹果,1是根,要删掉若干个分支,保留q个分支,问最多能保留几个苹果. 挺简单的树形DP,因为是二叉树,都不需要树上背包什么的. dp[u][k ...
- linux下查找可执行文件
linux下查找可执行文件 ls -F|grep "*" 我们来看看ls -F的作用: -F开关对可执行文件添加一个*号,为目录添加一个/号,为符号链接添加一个@号. http:/ ...
- SOAPUI测试步骤之断言测试(Assertion TestStep)
什么是没有办法验证结果的测试?soapUI提供了两种方法来测试断言:断言TestSteps现在断言一步步测试(PRO版本).The Assertion TestStep,扩展了断言处理和管理的想法.此 ...
- BZOJ3092 : [FDU2012校赛] A Famous King’s Trip
题目等价于去掉两条边,使得剩下的图连通,且所有点度数都为偶数. 首先特判掉图一开始就不连通的情况. 求出dfs生成树,对于每条非树边随机一个权值,每条树边的权值为所有经过它的非树边权值的异或和. 那么 ...
- js/jQuery判断浏览器名称、内核版本、浏览器壳
1.js方法 /* 判断浏览器名称和版本 目前只能判断:ie/firefox/chrome/opera/safari 2012年5月16日23:47:08 浏览器内核UA:UA; 浏览器内核名称:NV ...
- LinearLayout 垂直滚动条
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=" ...
- Android的Proxy/Delegate Application框架 (主要介绍插件化开发)
1. 插件化的原理 是 Java ClassLoader 的原理:Java ClassLoader基础 常用的其他解决方法还包括:Google Multidex,用 H5 代替部分逻辑,删无用代码,买 ...