Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Event Routing and events on buttons inside a ListBox
2 replies. Latest Post by trentnix on March 11, 2008.
(0)
trentnix
Member
128 points
32 Posts
03-10-2008 8:44 PM |
I am creating a set of buttons inside of a ListBox and am having trouble dynamically adding event handlers to deal with a situation where a button in the list has been clicked. Here's the setup:
I have a list box, let's call it _listBox and I have a set of classes called ButtonA, ButtonB, and ButtonC. These classes inherit from a base type of ButtonBase, which inherits from the Button control. I add these buttons dynamically to the listbox like so:
ButtonA a = new ButtonA();ButtonB b = new ButtonB();ButtonC c = new ButtonC();_listBox.Items.Add(a);_listBox.Items.Add(b);_listBox.Items.Add(c);_listBox.Height = a.Height + b.Height + c.Height;
Everything renders more or less like I expect it to. Within the constructor for ButtonBase (the class each button inherits from) I attach some event to the LeftMouseButtonUp event:
MouseLeftButtonUp +=
And DoAction has a signature of:
public
But every time I click the button, this event is not fired. I tried overriding the Click function in the base Button class and got the same result. I have verified that the constructor for ButtonBase is firing and that the line that adds the DoAction event handler to the MouseLeftButtonUp event does execute.
Help!
coder21
132 points
46 Posts
03-10-2008 11:09 PM |
this post should help
http://leeontech.wordpress.com/2008/03/11/adding-event-handlers-to-buttons-inside-a-listbox/
03-11-2008 12:11 AM |
Sorry I couldn't really follow what was being explained there. Why isn't the event being routed as I'm expecting?