TextBox UpdateSourceTrigger = PropertyChanged - does this really affect performance?

The MSDN documentation states:

Bindings that are TwoWay or OneWayToSource listen for changes to the target property and propagate them back to the source. This is called a source update. Typically, these updates occur whenever the goal of a property change. This is normal for checkboxes and other simple controls, but usually it is not suitable for text fields. Updating after each keystroke can reduce performance and it deprives the normal user of the opportunity to return and correct input errors before a new value. Therefore, the default value is UpdateSourceTrigger for the text property is LostFocus, not PropertyChanged.

I understand that in a situation where the update goes directly to the database or through the network, or if it is a very large amount of data, this can really reduce the performance for using UpdateSourceTrigger = PropertyChanged in text blocks.

But if it just updates a simple DependencyProperty or a property of an Entity Framework object (before the transaction), can performance be negligible?

It’s just interesting, because I am creating a WPF application that monitors the state of an edited object and optimizes the appearance of the Save button depending on whether changes have been made. I thought that the easiest way to detect changes would be to catch the relevant SourceUpdated events, if necessary. It works optimally when UpdateSourceTrigger = PropertyChanged for text fields, as the user receives instant feedback that there are "saved" changes.

+4
source share
2 answers

The reason you are being warned about performance degradation is because, for the most part, if you want the original property to be updated every time you press a key, it is because you need to happen something when the property value changes. After all, if you didn't need this “something,” you don't care when the property is updated, if it happens in the end.

The real impact on performance depends entirely on what it is. And it completely depends on your application. If this “something” formats and displays the value in another TextBlock , executing it with every keystroke will probably not be noticeable. If it filters 10,000 rows of a DataTable and updates a DataGrid , there will probably be associated ones.

So how do you say? Well, there are two ways:

1) Understand your application. If you know what the application does when you update the original property, you can predict whether it will do this every time you press a key, this will be a problem. When you say: “I guess I was wondering if it might look normal at first, but it can cause problems in certain situations that I don’t know about,” that you actually say: “What will happen, t know what mine does app when user presses a key? "

2) If you do not know what your application does when the user presses a key, profile it.

+1
source

If it is suitable for your application, and you have not noticed a significant performance degradation, then there is no problem installing UpdateSourceTrigger PropertyChanged . In fact, if you use an MVVM framework such as Caliburn.Micro , it will set this as the default value for all text fields.

+1
source

All Articles