I will tell you how to exit the application in UWP by the code.

We can call some static method to help us to exit the application.

The first method is as this code:

            CoreApplication.Exit();

And the other one is

Application.Current.Exit();

If you are making the WPF application that you can use this code to exit the application.

Application.Current.Shutdown();

And

Environment.Exit(0);

If you find any problems, please contact me.