-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom converter specified on binding is called only once at startup and not with the every OnPropertyChanged event #16137
Comments
You should consider writing an I can confirm the regression from 11.0.11 with the repro though (rc1 and nightly), so it should be fixed. Also, I see a use of |
As @stevemonaco said, this is a bit of an edge case as you're raising I cross-checked with WPF and it also does call the converter even if the value hasn't changed so I'm in two minds about whether we should support this use-case. On one hand we try to match WPF's behavior where it makes sense, but on the other hand it feels like this is an anti-pattern in that it's generally bad practise to rely on side-effects in bindings. It also feels like a misuse of |
I've run across a related issue to this that I never filed an issue for. The situation is this:
This is a pattern I've used since WPF as it saves one additional property on the view model that adds no new information. For now I've had to work-around this with a "IsListEmpty" property. I really wish the binding systems were smart enough to raise property change notification on the ListProperty when it's a collection that has INotifyCollectionChanged but we aren't there yet. So I've been using this method. Overall though, I think there always needs to be a way for apps to force re-evaluation of bindings. That's needed in edge cases we've discussed separately anyway. |
I provided the minimal sample to simulate this behavior. In real use I need to raise the property change for the property (flags) even if its value does not change because I need to translate the flags value into another language in runtime. I do not figure out another way how to do that. |
I think stateful converters are bad practice, but I also think the ViewModel or some component in-between should be responsible for restricting notifications, if necessary. To clarify my earlier answer: Use a |
lol, I've done it using the collection itself for so many years I never thought to check that. I never knew INotifyPropertyChanged fired for Count. Always learning, thanks!
I would say an Anyway, I still think we shouldn't try to outsmart application developers. Just as in WPF, if the view model wants an update it should get an update. I'm sure I can find other cases where it's needed if I looked a while. |
I've been thinking about this, and as much as I dislike some of the patterns this is used for, Avalonia 11.0 supports it and WPF supports it so Avalonia 11.1 should also support it. |
Describe the bug
Custom converter specified on binding is called only once at startup and not with the every OnPropertyChanged event as is expected. This is a new behavior related to 11.1.0-rc1, everything worked just fine with 11.0.10/11.0.11. Minimal sample to simulate this behavior is attached.
TestApp.zip
To Reproduce
Expected behavior
Text on the second line should change with the every click on button "Click me" because OnPropertyChanged event is fired for the binded property.
Avalonia version
11.1.0-rc1
OS
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: