Hey all.
I have a listbox, with a datatemplate defined.
In the datatemplate, lives a button.
How do I handle the click event of that button?
I've been looking for a while, and just can't figure it.
-
-
Oh, the DataTemplate is actually a usercontrol.
-
Aloha jh71283,
You should obtain instance of button and will add handler for click event. Instance should be obtained in override of OnAplyTemplate method of your usercontrol. -
Not enough detail to answer correctly. You've not stated your full goals, so your left with numerous options.
1. If the template isn't reused in multiple places, attach the handler directly to the button.
2. Use the routed nature of events in WPF to catch the click event on an ancestor control, such as the List itself. If you have more than one button in the template, you'll have to figure out how to differentiate between sources of the event.
3. Raise a more specific event from a click handler on the button.
4. Use a command instead of an event.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.