文章转载于https://www.cnblogs.com/dangnianxiaoqingxin/p/12653988.html

2.BindingGroup的使用

 public class MyClass
{
public int StartValue { get; set; }
public int EndValue { get; set; }
}
 public class RangeValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
BindingGroup bindingGroup = (BindingGroup)value;
MyClass mc = (MyClass)bindingGroup.Items[0];
int startValue = (int)bindingGroup.GetValue(mc, "StartValue");
int endValue = (int)bindingGroup.GetValue(mc, "EndValue");
bool isEnabled = (bool)bindingGroup.GetValue(mc, "IsEnabled"); if (startValue > endValue)
{
return new ValidationResult(true, null);
} return new ValidationResult(false, "Input should between 0 and 100");
}
}
 MyClass mc = new MyClass();
public MainWindow()
{
InitializeComponent(); this.DataContext = mc;
}
 <Grid Name="Grid1" Width="400" Height="300" >

        <Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.BindingGroup>
<BindingGroup NotifyOnValidationError="True">
<BindingGroup.ValidationRules >
<local:RangeValidationRule2 ValidationStep="ConvertedProposedValue" />
</BindingGroup.ValidationRules>
</BindingGroup>
</Grid.BindingGroup>
<TextBox Grid.Row="0" Name="tb1" Text="{Binding StartValue}"> </TextBox>
<TextBox Grid.Row="1" Text="{Binding EndValue}"/>
<Button Name="btn1" Content="btn1" Grid.Row="2" Click="Button_Click" > </Button>
</Grid>

验证:

  this.Grid1.BindingGroup.CommitEdit();

文章转载于https://www.cnblogs.com/dangnianxiaoqingxin/p/12653988.html

瞄到BindingGroup用法的更多相关文章

  1. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  2. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  3. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  4. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  5. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  6. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  7. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  8. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

  9. 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)

    vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...

随机推荐

  1. 安装centos出现的问题

    1.配置好之后,点击完成,如果出现"无法创建新虚拟机,无法打开配置文件,D:/... ,拒绝访问" 的错误时: 关闭虚拟机,重新以管理员身份打开.

  2. Mac开发必设置的Finder设置项,你设置了吗?

    1.显示标签页.显示路径栏.显示状态栏的设置位置,在访达->显示-> 显示状态栏 个人三个都设置了,但是觉得显示状态栏用的并不多,反而多一行,下面是显示状态栏的效果,主要可以一眼看出有多少 ...

  3. js动态加载js文件(js异步加载之性能优化篇)

    1.[基本优化] 将所有需要的<script>标签都放在</body>之前,确保脚本执行之前完成页面渲染而不会造成页面堵塞问题,这个大家都懂. 2.[合并JS代码,尽可能少的使 ...

  4. HashMap相关类:Hashtable、LinkHashMap、TreeMap

    前言 很高兴遇见你~ 在 深入剖析HashMap 文章中我从散列表的角度解析了HashMap,在 深入解析ConcurrentHashMap:感受并发编程智慧 解析了ConcurrentHashMap ...

  5. RDD、DF和DS的共性与区别

    共性: 1.都是spark平台下的分布式弹性数据集 2.都有惰性机制,创建.转换如map操作时不会立即执行,遇到foreach等Action算子时才开始运算. 3.都会自动缓存计算 4.都有parti ...

  6. .Net Core Excel导入导出神器Npoi.Mapper

    前言 我们在日常开发中对Excel的操作可能会比较频繁,好多功能都会涉及到Excel的操作.在.Net Core中大家可能使用Npoi比较多,这款软件功能也十分强大,而且接近原始编程.但是直接使用Np ...

  7. MySQL事务提交流程

    有binlog的CR方式(重点核心!!): 有binlog情况下,commit动作开始时,会有一个Redo XID 的动作记录写到redo,然后写data到binlog,binlog写成功后,会将bi ...

  8. gnuplot添加直线和箭头

    http://blog.csdn.net/bill_chuang/article/details/18215051 6.在图中添加直线和箭头 gnuplot> set arrow from 0. ...

  9. Abp vNext异常处理的缺陷/改造方案

    吐槽Abp Vnext异常处理! 哎呀,是一个喷子 目前项目使用Abp VNext开发,免不了要全局处理异常.提示服务器异常信息. 1. Abp官方异常处理 Abp项目默认会启动内置的异常处理,默认不 ...

  10. C# 数组 ArrayList List<T>区别

    System.Collenctions和System.Collenctions.Generic 中提供了很多列表.集合和数组.例如:List<T>集合,数组Int[],String[] . ...