简体   繁体   中英

How to close main window of uwp programmatically

Unlike wpf, uwp apps can't close their mainpage programatically. Window.Current.Close() fails when executed on mainpage of the app. What is the correct way of closing the mainpage in uwp??

Executing ApplicationView.GetForCurrentView().TryConsolidateAsync() in main window, closes it properly as if you have closed it by clicking close button in title bar. If app has only one window per instance this is preferred over Application.Exit() as this method suspends the app while Application.Exit() closes app abruptly. Also closing app by this method your app's previous position and size is remembered unlike for Application.Exit() .

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