How do I update the view after not changing the viewmodel binding source? #17131
Replies: 3 comments
|
I am actually facing the same problem: I have a setter of a property that corrects the user input. However, the UI only updates using this trick above. |
or even simpler:
No reason that the behavior of a control should be implemented in a ViewModel. |
|
I'm coming from WPF where the same code works as expected. Viewmodel: Binding: I don't even know exactly where this behavior in Avalonia differs from WPF. But I can see that it's not due to LostFocus. Even PropertyChanged produces confusing behavior in Avalonia, whereas in WPF it works as you'd expect: the text is always capitalized. |




Uh oh!
There was an error while loading. Please reload this page.
I have a
TextBoxwith aMode=TwoWaybinding to a ViewModel andUpdateSourceTrigger=LostFocus. In the ViewModel, whitespace gets trimmed on setting, something like this:In other words, upon losing focus, i want the
TextBoxto update and remove all whitespace at the start and end. The issue is that, when the only thing i do is add whitespace, the value behind the binding does not change, and so the text in the UI does not change either, meaning the whitespace remains.I have no idea how to properly make it update and have it remove the whitespace after adding whitespace, but i did find a reliable workaround:
Essentially, i do make a change, tell the ui to update with it, change it back, and tell the UI to update again. This works, but is ugly. Is there a better solution?
Workaround in action:

All reactions