I have a user control with several buttons, which need to take different actions depending on the class using it.
The problem is that I don't know how to implement those handlers because when using my user control from the final app I don't have direct access to the buttons to specify which handler handles which events.
How would you do that?
Another way to do this is to expose the events through events in your UserControl :
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public event RoutedEventHandler Button1Click;
private void button1_Click(object sender, RoutedEventArgs e)
{
if (Button1Click != null) Button1Click(sender, e);
}
}
This gives your usercontrol a Button1Click
event that hooks up to that button within your control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With