Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Common event fired for value changed

Ok. This seems like an incredibly basic use case but fore some reason I am having an issue finding a common solution across control types.

Heres the use case:

A form is presented to the user with any editable controls. (Text box, combo, grid etc.).

The user edits a value in the control and tabs out.
Expectation is that I can wire to an event like Lost Focus and do "foo" with the changed value.

The user then gives focus back to the control and tabs out without making an edit. Expectation is that whatever event I am wired to I can check if the value has been changed.

Is there one common event across controls that will only fire when the user has finished editing( such as tab out or enter ) and allow me to check previous state vs. current state?

like image 443
Jason Burke Avatar asked Nov 12 '22 20:11

Jason Burke


1 Answers

Jason, you may want to look into Binding and DependencyProperties in WPF instead of tracking events in your form. You would bind a class to your form which exposes properties to be changed. Using DependancyProperties a single event is fired called "PropertyChanged".

Unfortunately is is a broad topic, but you will really get the full benefit of the WPF programming model. Searches on "dependency properties in wpf" will give you some good examples.

like image 152
Spevy Avatar answered Nov 15 '22 09:11

Spevy