Soumya Mahunt
Soumya Mahunt

Reputation: 2762

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??

Upvotes: 1

Views: 1033

Answers (1)

Soumya Mahunt
Soumya Mahunt

Reputation: 2762

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().

Upvotes: 1

Related Questions