I want to invoke a button click event automatically when the WPF form loads. So I'm calling it in the constructor right before initializeComponent();. But it always gives me the following error: System.NullReferenceException: 'Object reference not set to an instance of an object.'
the code is:
logoutBTN.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
how can I fix this?
EDIT, SOLUTION This does the job! Thanks.
Loaded += (s, e) => logoutBTN.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));