How to bind an event to multiple items? I need for example to add a click event to several already existing controls, like in jQuery

$(".element").click(function(){ if(this.что_то_там){ } }) 

and how to use a reference to the current this object inside a function?

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky
  • You need to implement the Observer pattern. Use delegates. Why can't I write the answer to this question? I can only comment - Max

1 answer 1

Well, for example with the help of a cycle, if you have a list of elements:

 foreach (var t in runningTasks) t.Completed += result => results.Add(result);