CommandBarControl Click Event is not Working!!!!

2. September 2012 00:15 by Mrojas in   //  Tags: , , , , ,   //   Comments (0)

Today I was doing a VS extention as part of my weekend relaxation activities ;)

Everything was great until succendly something was not happening as I expected.

 I was adding a context menu to the code window with a dynamic list of options.

And each option had a different click delegate, but my click events were

disrespectfully discarted.

 Luckily I found this post:  http://www.rauchy.net/blog/?cat=4&paged=2

 And now for a tricky part: since you ge\t your instance of CommandBarEvents inside the scope of a method, when the method ends, the Garbage Collector collects it, leaving all the event handlers orphaned. Unless you keep your instance safe from the jaws of the mighty Garbage Collector, your buttons will not respond to clicks.

To do so, just keep your CommandBarEvents instance(s) as member fields of your class. Once your class is disposed, they will be disposed as well.

 Thanks Rauchy you saved my day! (And my wife is happy because I'm finally getting out of the bathroom :P)

Categories