Alex Rivera | Logout

How can I execute code when value of a variable changes in C#?

Asked 2009-07-16T10:05:53.670
9

I want to toggle a button's visibility in when value of a particular variable changes. Is there a way to attach some kind of delegate to a variable which executes automatically when value changes?

Edit
Report

1 Answer

0

You either have a reference to the GUI in your model (where the variable is) and directly perform the GUI change in the setter method, or you make your GUI observe your model via an observer, and have the observable model fire events to the observers in the setters. The former will lead to spaghetti code eventually, as you add more and more direct links between model and view, and thus should only be used for in-house tools and simple programs.

answered 2009-07-16T10:13:01.177

Your Answer