简体   繁体   English

如何以编程方式关闭 uwp 的主要 window

[英]How to close main window of uwp programmatically

Unlike wpf, uwp apps can't close their mainpage programatically.与 wpf 不同,uwp 应用程序无法以编程方式关闭其主页。 Window.Current.Close() fails when executed on mainpage of the app. Window.Current.Close()在应用程序的主页上执行时失败。 What is the correct way of closing the mainpage in uwp?? uwp中关闭主页的正确方法是什么?

Executing ApplicationView.GetForCurrentView().TryConsolidateAsync() in main window, closes it properly as if you have closed it by clicking close button in title bar.在主 window 中执行ApplicationView.GetForCurrentView().TryConsolidateAsync()会正确关闭它,就像您通过单击标题栏中的关闭按钮关闭它一样。 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.如果应用程序每个实例只有一个 window,则此方法优于Application.Exit() ,因为此方法会暂停应用程序,而Application.Exit()会突然关闭应用程序。 Also closing app by this method your app's previous position and size is remembered unlike for Application.Exit() .同样通过这种方法关闭应用程序,您的应用程序以前的 position 和大小会被记住,这与Application.Exit()不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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