Skip to content
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

Add a runtime switch option to disable ValueChangedEventManager #10148

Open
zlatanov opened this issue Dec 6, 2024 · 4 comments
Open

Add a runtime switch option to disable ValueChangedEventManager #10148

zlatanov opened this issue Dec 6, 2024 · 4 comments

Comments

@zlatanov
Copy link

zlatanov commented Dec 6, 2024

When binding to objects which do not implement INotifyPropertyChanged interface, the underlying data binding engine will use an obscure mechanism to try and listen to changes in any .NET object - ValueChangedEventManager.

Please, add a switch which disables this functionality. All WPF developers know that if we want change notifications, we should implement INotifyPropertyChanged.

This will improve the overwall WPF data binding performance, because there are a lot of cases where we need to databind to something (e.g. Length property of an array) which doesn't implement INotifyPropertyChanged.

@miloush
Copy link
Contributor

miloush commented Dec 6, 2024

All WPF developers know that if you care about performance and bind to something that you know doesn't change, you should use OneTime binding mode. By not doing so, you are literally telling WPF to do whatever it can to keep up with the changes.

Type descriptors are well documented .NET mechanism and WPF intentionally supports them, see e.g. Binding Sources Overview or Optimizing Performance: Data Binding. If I rely on it in a library, I wouldn't want someone using my library to break it by disabling it in their application.

@zlatanov
Copy link
Author

zlatanov commented Dec 6, 2024

All WPF developers know that if you care about performance and bind to something that you know doesn't change, you should use OneTime binding mode. By not doing so, you are literally telling WPF to do whatever it can to keep up with the changes.

This only works for the simplest of cases. If we have a chained path where everything in it supports INotifyPropertyChanged, but the last few properties, we cannot do it.

Also I don't want to break the binding to such properties. I want to disable the framework to helplessly try to subscribe for changes in such cases.

@MichaeIDietrich
Copy link
Contributor

I would say, it is not only about performance but also about leaking memory.
It's a recurring trap which especially unexperienced devs will unintendedly step into. It's fairly easy to overlook that some part of a binding expression is neither a DependencyProperty nor backed by INotifyPropertyChanged.
And while intentions to fall back to PropertyDescriptor were most probably good, I would guess that it is probably doing more harm than good.

I would agree that it would be nice, if the behavior can be controlled in some way.

@miloush
Copy link
Contributor

miloush commented Dec 6, 2024

A chained path is a good point that is not easily covered by binding mode.

A memory leak is a different issue. If there is a memory leak, then we should fix the memory leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants