英文:
In MAUI, how to restore an app to be the visually on top of all other apps?
问题
如果一个 MAUI 应用在视觉上被放置在其他应用程序后面,但发生了需要将其置于视觉前景以便用户立即响应的事件,跨平台需要采取哪些过程步骤?一旦响应完成,如何将其重新定位到原来的位置?
英文:
If a MAUI app has been repositioned visually behind other apps, but an event occurs that requires it to be brought to the visual foreground for the immediate response of the user, what process steps are required across the platforms? Once responded to, how do you reposition it to where it was?
答案1
得分: 2
对于 Android 和 iOS,您无法使应用程序显示在所有其他应用程序的顶部,因为这应该取决于用户。在应用程序在后台运行时,您应该使用 Toast、Alert 或 Notification,而不是整个应用程序显示。
对于 Windows,请在想要将应用程序显示在所有其他应用程序上方时使用以下代码:
#if WINDOWS
Microsoft.UI.Xaml.Window window = (Microsoft.UI.Xaml.Window)App.Current.Windows.First<Window>().Handler.PlatformView;
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
Microsoft.UI.Windowing.AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
(appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).IsAlwaysOnTop = true;
(appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).IsAlwaysOnTop = false;
#endif
英文:
For the Android and iOS, you can't make your app show on top of all other apps, because this should depend on the users. And you should use the Toast, Alert or Notification instead of the whole app show when your app is in the background.
And for the Windows, you can use the following code when you want to show your app on top of all other apps:
#if WINDOWS
Microsoft.UI.Xaml.Window window = (Microsoft.UI.Xaml.Window)App.Current.Windows.First<Window>().Handler.PlatformView;
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(window);
Microsoft.UI.WindowId windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle);
Microsoft.UI.Windowing.AppWindow appWindow = Microsoft.UI.Windowing.AppWindow.GetFromWindowId(windowId);
(appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).IsAlwaysOnTop = true;
(appWindow.Presenter as Microsoft.UI.Windowing.OverlappedPresenter).IsAlwaysOnTop = false;
#endif
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论