I need to be able to get and set the textbox’s text, but I don’t want every single change in the textbox’s text to update a string in my viewmodel. It seems to me that binding a string to the textbox’s text property would be nearly as inefficient as updating a string on a textbox’s textchanged event or am I wrong?
Share
The default UpdateSourceTrigger for bindings to
TextBox.TextisLostFocus, which means that the string in your viewmodel is only updated when the TextBox is left.Of course, if you do something like this
then your string will be updated every time something changes in the text box. So, yes, it would be “nearly as inefficient as updating a string on a textbox’s textchanged event”.
Still, I don’t see a real-world problem here: Even if you have a very fast typing user, updating a string in memory is not an operation that takes a terrible amount of time. In fact, processing the user input by the TextBox itself (showing the characters typed, scrolling the text to the left if the end of the box is reached, etc.) also needs quite a bit of processing, so I don’t think updating your string creates such an unreasonable additional burden.