How can I call SubGraphButton_Click(object sender, RoutedEventArgs args)
from another method?
private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }
How can I call SubGraphButton_Click(object sender, RoutedEventArgs args) from another method? private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { // call SubGraphButton-Click(). }
A button click event is there to do what it says on the tin - handle the button click. The enclosed functionality is simply you saying "I'd like to do this when this happens". Extending this further you could make DoButtonStuff public and call it from elsewhere as you would with any other method.
PerformClick() works for any number of event handlers attached to Button2. Click (e.g. another form might have attached this event with AddHandler ), where as Button2_Click(sender, e) calls a specific handler.
To simulate the button click in code, you simply call the event handler: Button1_Click(object sender, EventArgs e). protected void Page_Load(object sender, EventArgs e) { //This simulates the button click from within your code. Button1_Click(Button1, EventArgs.
You can easily do it by the following piece of code (assuming that name of your button is btnButton):
btnButton.PerformClick();
You can call the button_click event by simply passing the arguments to it:
private void SubGraphButton_Click(object sender, RoutedEventArgs args) { } private void ChildNode_Click(object sender, RoutedEventArgs args) { SubGraphButton_Click(sender, args); }
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