更新数据绑定上失去焦点 [英] Update Databinding on lost focus

查看:157
本文介绍了更新数据绑定上失去焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了WPF有 UpdateSourceTrigger 的属性,将允许数据绑定发生后控制已失去焦点,是有WinForms的类似的东西?



我遇到在那里更新数据绑定值时,整个源改变,而不是单个属性的问题。



这是害我一个问题,因为我有一个复选框,改变选中状态时,更新具有相同的数据绑定源,这使得数据绑定另一个源我的复选框永远不会改变的价值(或者更确切地说,它确实又换了回来)



我创建了一个的示例程序演示此。 (有一个复选框和文本框的基本形式)



另外,有另一种方式来处理我的数据绑定,使只有数据绑定属性值的变化而不是源<? / p>

解决方案

在最后我不得不手动更新数据绑定withith的的CheckedChanged 事件。



例如,使用我的示例程序的源。

  checkBox1.CheckedChanged + =(S,E)=> {
dc.BooleanVal =((复选框)S).checked;
customControl1.Text =3;
label1.Text = dc.BooleanVal.ToString(); };


I've seen that WPF has a UpdateSourceTrigger property that will allow for data binding to take place after a control has lost focus, is there something similar for winforms?

I've come across an issue where when updating a databound value, the entire source is changed rather than the single property.

This is causing me a problem as I have a CheckBox that when changed checked state, updates another source that has a databinding from the same databinding source, which makes my checkbox never change value (or rather it does then changes it back)

I've created an example program that demonstrates this. (Basic form with a checkbox and text box)

Alternatively, is there another way to handle my databinding to make only the data bound property value change instead of the source?

解决方案

In the end I had to manually update the databinding withith the CheckedChanged event.

For example, using the source for my example program.

checkBox1.CheckedChanged += (s, e) => { 
  dc.BooleanVal = ((CheckBox)s).checked;
  customControl1.Text = "3"; 
  label1.Text = dc.BooleanVal.ToString(); };

这篇关于更新数据绑定上失去焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆