Jason Axelrod
Jason Axelrod

Reputation: 7805

WPF Executing function in user control on application close?

I have a bunch of user controls in my application. When I close my application, I want to fire off some specific functions in each of these user controls one-by-one. Is this possible? The Unloaded event doesn't seem to get fired on application close.

Upvotes: 1

Views: 398

Answers (1)

Alexandre Veya
Alexandre Veya

Reputation: 95

You can register to

Application.Current.Exit

in each UserControl.xaml.cs:

        public MyUserControl()
    {
        InitializeComponent();
        Application.Current.Exit += CurrentOnExit;
    }

    private void CurrentOnExit(object sender, ExitEventArgs exitEventArgs)
    {
        Application.Current.Exit -= CurrentOnExit;
        //Do what you want
    }

Upvotes: 1

Related Questions