文章转载于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

最新文章

  1. &lt;2016-2-2 总结&gt;
  2. WEB文件上传漏洞介绍解决办法
  3. [Node.js] 使用File API 异步上传文件
  4. BZOJ3246 [Ioi2013]Dreaming
  5. jquery之event与originalEvent的关系、event事件对象用法浅析
  6. 读《我是一只IT小小鸟》有感
  7. POJ 1422
  8. ASP.NET MVC自定义路由 - 实现IRouteConstraint限制控制器名(转载)
  9. FIREDAC调用中间件远程方法查询数据示例
  10. JavaScript跨站脚本攻击
  11. XML实例文档
  12. Windows下WordPress搭建博客过程
  13. 关于vue的computed、filters、watch
  14. echarts功能配置实例----柱/折线、饼图
  15. curl与wget
  16. C#闰年判断
  17. Testing - 软件测试知识梳理 - 理解测试
  18. 使用第三方工具Xtrabackup进行MySQL备份
  19. linq partion by 用法
  20. javascript中常见错误类型

热门文章

  1. bugkuctf 这 是 一 个 神 奇 的 登 录 界 面
  2. 步步为营,打造CQUILib UI框架库
  3. Python 反序列化漏洞学习笔记
  4. Windows的API功能查询
  5. Vue:对axios进行简单的二次封装
  6. thinkphp thinkphp6 安装JWT
  7. AOP 有几种实现方式?
  8. Nginx(四):Keepalived+Nginx 高可用集群
  9. Java中字符串替换方法
  10. css 16-浏览器的兼容性问题