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