简体   繁体   中英

How to close a Windows 8 application programmatically?

I'm building an application for Windows 8 and need to be able to close it programmatically using an action. For example, a button on my application.

I'm building my application using HTML5

The following event handler worked for me...I actually put an Exit icon in a global app bar...users love it!

        private void closeButton_Click(object sender, RoutedEventArgs e)
        {
            App.Current.Exit();
        }

Good Luck!

This solution above works for C#...it's especially helpful when using Windows 8 Store Apps on machines that are not touch screen capable (our users were having difficulty emulating the top down swipe to close an app...other users are running a Windows 8 on a Mac VM which makes the Alt + F4 tough)

You cannot. The Windows Runtime API (and the modern subset of the windows SDK) don't provide mechanisms to terminate applications.

The model for Windows Runtime based applications is to allow the system or the user to manage the process lifetime.

在JS中你可以这样做:

window.close();

您无法以编程方式关闭应用程序,这是系统的选择。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM