在MAUI中,如何将应用程序恢复到视觉上位于所有其他应用程序之上?

huangapple go评论70阅读模式
英文:

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,您无法使应用程序显示在所有其他应用程序的顶部,因为这应该取决于用户。在应用程序在后台运行时,您应该使用 ToastAlertNotification,而不是整个应用程序显示。

对于 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>



huangapple
  • 本文由 发表于 2023年5月17日 20:30:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76272128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定