I am working in wpf – mvvm model.
I have a textbox which holds- “marketName”. In xaml I am binding the property – “newmarketname”(which is defined in my viewmodel) to this textbox. Once if user enter a new market name in that text box, the “set” method of the “newmarketname” get called.
In set method of the “newmarketname”, I call the PropertyChanged event.
And the property changed handler will call a fucntion, in which I check if the market name is already existing; if “yes”, I will assign string.Empty to the property “newmarketname”.
So the set method of “newmarketname” again get called followed by PropertyChanged event.
But the issue is: even though the value of “newmarketname” is getting changed to empty, it is not getting reflected in the UI.
What’s the issue?
WPF will ignore PropertyChanged events that are raised while it is setting the value. One workaround is to use a Converter (even one that just returns the raw value) and set UpdateSourceTrigger to LostFocus. Another is to set IsAsync to True.
This has been fixed in .NET 4.0. See this blog entry for more information: http://karlshifflett.wordpress.com/2009/05/27/wpf-4-0-data-binding-change-great-feature/