c# - How to avoid a databinding / events hell on a complex screen? -


this more of architecture / design question.

i have run few projects in past written in wpf/windows forms, etc. have complex screens lot of fields , these fields connected each other (their values depend on each other logic involved).

these projects have taken on after implemented, , found lot of events / data bind hell - mean because these fields depending on others have implemented inotifypropertychanged , other fields being modified result. causes same fields being updated 5-6 times when screen loads , order in fields populated causes horrible bugs. (for example, date set before job type, instead of after job type, end different job fee.)

to make matters worse, hacks implemented on ui events (for example, dropdown changed update field x) while others in domain model ui binds to.

basically, it's huge mess, , want know best way implement if start scratch. or idea avoid such complex screen in first place?

i try keep business logic out of property setters as possible.

first of all, if several properties needed 1 calculation, i'd write 1 method calculation, , call method when appropriate. e.g. if different combinations of property values make sense, 1 call method in setters of each property, making sure same code runs time 1 of properties changed. if can evaluate special combinations of property values, either implement command , let user decide when calculate resulting changes, or provide feedback through validation, , evaluate property changes if combination valid. if there several interdependent properties, use "changeinitiator" variable indicate property has changed, clear in calculation method property responsible change , others should change result. basically, same doing 1 part of calculation in each property setter, find helps me keep overview of things if different parts of relationship in 1 method.

in program wrote once, had calculations running on background thread periodically, set flag whenever piece of data changed required new calculation, , updates based on timer every second or so... logic more straight, , avoids have calculation run several times 1 set of related changes.

with regard change notification, i'd try use ui data binding.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -