Hello All
i want to FIre the button Click event When My Window is Loaded.. How Can i Achieve it in Wpf.
thanks in advance
shashank
Hello All
i want to FIre the button Click event When My Window is Loaded.. How Can i Achieve it in Wpf.
thanks in advance
shashank
Create a single function with the shared behavior in your window, then call that function from both your loaded handler and your click handler.
in you page_loaded event handler method, make a call to the click event like this:
_buttonName_click(sender, new RoutedEventArgs())
You could use Automation
to do it aswell - I've seen this suggested some places as the more flexible/robust method to use, but it seems a bit heavy weight to me compared to just calling the method you already have directly.
As per this blog post in WinForms this was really easy by just calling PerformClick(), but in WPF you can do it with Automation, however as a commenter mentioned it's really easy if you have access to the button to just use RaiseEvent
.
someButton.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
But as previously answered, if you only have a single handler that needs to be notified, then simply call that handler method directly.