M
Mikus Sleiners
I have a control - textBox1 that is binded to objects propery - "Currency"
and another control - textBox2 (read only) that is also binded to same
propery.
Now, i have a situation where textbox1 control does NOT refresh it's display
according to value set to underlying propery while at the same time
textBox2 does refresh accordingly.
Both textboxes ar located on the same form and there are no diferences in
their bindings.
private int _currency = (int)cur.LVL;
public int Currency
{
get { return _currency; }
set
{
if(!_currency.Equals (value))
{
if(value == 2)
{
// Consider according to some business logic not shown here,
value should be changed from 2 to 3
value = 3;
}
_currency = value;
if(PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs
("Currency"));
}
}
}
}
The scenario that produces incorrect response is following:
1) By default when i open form propery has value of 1, so both textboxes
contain value of 1 (textBox2 is readonly)
2) I change value in textBox1 from 1 to 3 => binding does it's job and both
textBoxes now contain value of 3. This is correct
3) Now i change value in textBox1 from 3 to 1 => binding does it's job and
both textBoxes now contain value of 1. This is also correct
4) Now let's change value in textBox1 from 1 to 2 (as you can see in code
above - value of 2 will not be set as it get's changed by business logic
from 2 to 3, so 3 is set) =>
now textBox2 displays correct value of 3, but textBox1 still shows 2... it
looks like binding does not refresh on control that have initialized the
change of value.
I tried to rewrite property this way:
public int Currency
{
get { return _currency; }
set
{
if(!_currency.Equals (value))
{
_currency = value;
if(PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs
("Currency"));
}
if(value == 2)
{
_currency = 3;
}
if(PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs
("Currency"));
}
}
}
}
but it does not help either.
Final info: my object class is inherited from INotifyPropertyChanged and
does contain :
// Event for handling data changes
public event PropertyChangedEventHandler PropertyChanged;
Any ideas on how to solve this ?
and another control - textBox2 (read only) that is also binded to same
propery.
Now, i have a situation where textbox1 control does NOT refresh it's display
according to value set to underlying propery while at the same time
textBox2 does refresh accordingly.
Both textboxes ar located on the same form and there are no diferences in
their bindings.
private int _currency = (int)cur.LVL;
public int Currency
{
get { return _currency; }
set
{
if(!_currency.Equals (value))
{
if(value == 2)
{
// Consider according to some business logic not shown here,
value should be changed from 2 to 3
value = 3;
}
_currency = value;
if(PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs
("Currency"));
}
}
}
}
The scenario that produces incorrect response is following:
1) By default when i open form propery has value of 1, so both textboxes
contain value of 1 (textBox2 is readonly)
2) I change value in textBox1 from 1 to 3 => binding does it's job and both
textBoxes now contain value of 3. This is correct
3) Now i change value in textBox1 from 3 to 1 => binding does it's job and
both textBoxes now contain value of 1. This is also correct
4) Now let's change value in textBox1 from 1 to 2 (as you can see in code
above - value of 2 will not be set as it get's changed by business logic
from 2 to 3, so 3 is set) =>
now textBox2 displays correct value of 3, but textBox1 still shows 2... it
looks like binding does not refresh on control that have initialized the
change of value.
I tried to rewrite property this way:
public int Currency
{
get { return _currency; }
set
{
if(!_currency.Equals (value))
{
_currency = value;
if(PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs
("Currency"));
}
if(value == 2)
{
_currency = 3;
}
if(PropertyChanged != null)
{
PropertyChanged (this, new PropertyChangedEventArgs
("Currency"));
}
}
}
}
but it does not help either.
Final info: my object class is inherited from INotifyPropertyChanged and
does contain :
// Event for handling data changes
public event PropertyChangedEventHandler PropertyChanged;
Any ideas on how to solve this ?