Reputation: 1796
I've developing a Windows 8 app using .NET 4.5 in visual studio 2012 ultimate.
The problem I have is that if I can the text value of lets say a TextBox in code the OnChanged event gets fired an what seems like an unpredictable manner and the code in the OnChanged event handler gets fired when I don't want it to.
For example
In the OnChanged event handler I might have some code that updates the app status to "Editing.." when the user changes the text in the TextBox. However I don't want the status to be changed if I change the text myself in code.
So I created a global variable called "Updating" which controls if the code in the OnChanged event can run or not.
I set updating to true, then set the textbox text property to some value and set the Updating variable to false. Problem is that the OnChanged event of the TextBox seems to be getting fireed after I have set the Updating variable to false causing the code in the event handler to be fired.
I guess this has something to do with the async nature of Win 8 apps.
Does anyone know how I can resolve this issue? Some background information on this behvaiour would also be helpful.
Upvotes: 1
Views: 206
Reputation: 26
I having just the same behavior and don't know how to resolve it. I also have an global variable IsUpdating which is set during programmatically update of a textbox.Text and which is intended to exit the TextChanged event. But as Adi mentioned above. These events fire after having leaved the update method and so IsUpdating is reset to false. As a consequence the event entirely executed and my Modified-Flag is set.
This problem has been reported to the app-hotline and is hopefully solved very soon.
Upvotes: 0
Reputation: 206
Why dont remove the eventhandler before updating the text and adding it afterwards?
Upvotes: 2