binding with timer
-
Hello, I have a textBox which has binding to a property of a ViewModel. I want the ViewModel to execute a method if the textbox is not empty and if user didn't change the text in the textbox for 2 seconds. I mean only if user wrote something and waited for 2 seconds, than the method will execute. How can i do it?
-
Hello, I have a textBox which has binding to a property of a ViewModel. I want the ViewModel to execute a method if the textbox is not empty and if user didn't change the text in the textbox for 2 seconds. I mean only if user wrote something and waited for 2 seconds, than the method will execute. How can i do it?
Have a timer in the VM Have the onchange event in the model for the field reset the timer (and clear the cache string, possibly) In the tick method check the content of the field if != string.empty and matches the cached string then call your method Cache the string Onchange of the selected item always clear the cache string
Never underestimate the power of human stupidity RAH
-
Have a timer in the VM Have the onchange event in the model for the field reset the timer (and clear the cache string, possibly) In the tick method check the content of the field if != string.empty and matches the cached string then call your method Cache the string Onchange of the selected item always clear the cache string
Never underestimate the power of human stupidity RAH
Sounds like too much work. When he adds a 2nd edit box / timer, he'll have to copy & paste all that crap. Better solution would be to write a "TextBoxEx" control that encapsulates the behavior so it is easier to reuse and you don't have to dick around with forwarding a bunch of stuff to the VM.
-
Sounds like too much work. When he adds a 2nd edit box / timer, he'll have to copy & paste all that crap. Better solution would be to write a "TextBoxEx" control that encapsulates the behavior so it is easier to reuse and you don't have to dick around with forwarding a bunch of stuff to the VM.
SledgeHammer01 wrote:
When he adds a 2nd edit box / timer
Only applies if this rather esoteric requirement needs to be duplicated, but yes I think I'd do with the textboxex out of good design principles (never write code twice)
Never underestimate the power of human stupidity RAH