I hope someone can help me with this one, I suspect I am doing something stupid. I have bound a TextBox so that the Text is bound to InputValue. Basically, when the text value changes I have a method (Inches.Parse), which examines the value and returns a well formatted string.
If there are no errors with the parsing I want the textbox to have the well formatted string called “result”. However, the TextBox won’t show the new text? Any help would be appreciated.
public string InputValue
{
get
{
return _inputValue;
}
set
{
if (_inputValue != value)
{
bool error;
string result = Inches.Parse(value, 64, out error);
if (error != IsValid)
{
IsValid = error;
}
if (!error)
{
_inputValue = result;
}
else
{
_inputValue = value;
}
NotifyPropertyChanged("InputValue");
}
}
}
This is a bug/issue that will apparently be fixed in dot net 4.0
Basically the problem is that if a binding sets a property it does not look for
NotifyPropertyChangedduring the setter. you can workaround this issue, by callingNotifyPropertyChangedon the main ui thread with a dispatcher. it is done like thisput this in your setter and you should be fine..