文章转载于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. 软工个人项目 ——wc.exe

    1.GitHub项目地址 https://github.com/k8kiw/WordCount 2.PSP预计时间 PSP2.1 Personal Software Process Stages 预估 ...

  2. cookie的理解

    第一:每个特定的域名下最多生成20个cookie IE6或更低版本最多20个cookie IE7和之后的版本最多可以有50个cookie Firefox最多50个cookie chrome和Safar ...

  3. P6100 [USACO19FEB]Painting the Barn G

    本题解提供的做法思路应该是比较清晰的,可惜代码实现比较繁琐,仅供大家参考. 题解 不难发现 \(x\) ,\(y\) 的取值范围只有 \(200\) ,所以我们可以考虑从这里入手.我们可以先通过二维前 ...

  4. 题解-[SDOI2016]征途

    [SDOI2016]征途 [SDOI2016]征途 给定长度为 \(n\) 的序列 \(a\{n\}\),将其分为连续 \(m\) 段,和分别为 \(v\{m\}\).\(v\{m\}\) 的方差为 ...

  5. 关于svg格式问题

    背景介绍: 在使用photoswipe的时候,引入了css,按钮是使用svg进行展示的,在用vs2010开发调试过程中,发现不能显示按钮.在请求.svg 的文件时,响应头中的content Type始 ...

  6. .NET Core +Angular 项目 部署到CentOS

    前言: 最近公司需要开发项目能在Linux系统上运行,示例开发项目采用.Net Core + Angular开发:理论上完全支持跨平台. 但是实践才是检验真理的唯一标准:那么还是动手来验证实现下:过程 ...

  7. SpringBoot + SpringSecurity + Quartz + Layui实现系统权限控制和定时任务

    1. 简介   Spring Security是一个功能强大且易于扩展的安全框架,主要用于为Java程序提供用户认证(Authentication)和用户授权(Authorization)功能.    ...

  8. 面试 11-01.ES6:模块化的使用和编译环境

    11-01.ES6:模块化的使用和编译环境 #前言 #ES6的主要内容 模块化的使用和编译环境 Class与JS构造函数的区别 Promise的用法 ES6其他常用功能 本文来讲"模块化的使 ...

  9. Numpy的学习4-array的合并

    import numpy as np A = np.array([1, 1, 1]) B = np.array([2, 2, 2]) print(np.vstack((A, B))) # vertic ...

  10. Google、Facebook等均开始支持的HTTP3到底是个什么鬼?

    GitHub 19k Star 的Java工程师成神之路,不来了解一下吗! 最近一段时间以来,关于HTTP/3的新闻有很多,越来越多的国际大公司已经开始使用HTTP/3了. 所以,HTTP/3已经是箭 ...