G
Guest
I am currently writing a compact framework application with uses the data
binding capabilities of windows forms controls. In this application, I am
binding controls (mainly text boxes) to a custom object type, with properties
defined suitable for binding to (including the associated propertyChanged
event types defined so that changes on these properties will be propagated to
the control).
The problem I am experiencing is that if the value of a text box is changed,
this change is not propagated to the property on the custom object until this
control loses focus (the user selects another control, or presses tab, etc).
Is this a documented "feature" of data binding to text fields, or am I doing
something wrong?
The class I'm binding to is defined thus (with the irrelevant details
omitted):
public class Values {
private string curVal;
public string CurrentValue
{
get
{
return curVal;
}
set
{
Console.WriteLine("current value changing");
curVal = value;
OnCurrentValueChanged();
}
}
private void OnCurrentValueChanged()
{
if (CurrentValueChanged != null)
{
CurrentValueChanged(this, new EventArgs());
}
}
public Binding getCurrentValueBinding(String controlProp)
{
return new Binding(controlProp, this, "CurrentValue");
}
}
The control is bound to a Values instance as follows:
TextBox textBox = ...
Values values = ...
textBox.DataBindings.Add(values.getCurrentValueBinding("Text"));
binding capabilities of windows forms controls. In this application, I am
binding controls (mainly text boxes) to a custom object type, with properties
defined suitable for binding to (including the associated propertyChanged
event types defined so that changes on these properties will be propagated to
the control).
The problem I am experiencing is that if the value of a text box is changed,
this change is not propagated to the property on the custom object until this
control loses focus (the user selects another control, or presses tab, etc).
Is this a documented "feature" of data binding to text fields, or am I doing
something wrong?
The class I'm binding to is defined thus (with the irrelevant details
omitted):
public class Values {
private string curVal;
public string CurrentValue
{
get
{
return curVal;
}
set
{
Console.WriteLine("current value changing");
curVal = value;
OnCurrentValueChanged();
}
}
private void OnCurrentValueChanged()
{
if (CurrentValueChanged != null)
{
CurrentValueChanged(this, new EventArgs());
}
}
public Binding getCurrentValueBinding(String controlProp)
{
return new Binding(controlProp, this, "CurrentValue");
}
}
The control is bound to a Values instance as follows:
TextBox textBox = ...
Values values = ...
textBox.DataBindings.Add(values.getCurrentValueBinding("Text"));