c# - 如何以编程方式将 UWP 应用程序从后台(最小化模式)带到前台?

标签 c# uwp

我已经尝试了很多选项,以编程方式将 UWP 应用程序从最小化模式带到前台(所有正在运行的应用程序的顶部),但根本没有成功:(,以下是我尝试执行的相同操作的选项,如下所示:-

1:代码:- 等待 Windows.System.Launcher.LaunchUriAsync(new Uri("yourprotocolhere://"));`

它启动但无法将 带到前台,但它使应用程序在任务栏中闪烁。

2 代码:- protected 覆盖​​ void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Protocol) { ProtocolActivatedEventArgs eventArgs = args 作为 ProtocolActivatedEventArgs;

                // Get the root frame
                Frame rootFrame = Window.Current.Content as Frame;

                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (rootFrame == null)
                {
                    // Create a Frame to act as the navigation context and navigate to the first page
                    rootFrame = new Frame();

                    rootFrame.NavigationFailed += OnNavigationFailed;

                    if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                    {
                        //TODO: Load state from previously suspended application
                    }
                    // Place the frame in the current Window
                    Window.Current.Content = rootFrame;
                }
                rootFrame.Navigate(typeof(AppRootContainer));
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }

结果与上面相同。

3:我什至尝试过具有受限功能“runFullTrust”的桌面扩展来启动/将应用程序带到前台,但仍然没有成功。

任何人都可以指导我实现相同的目标,或者想知道是否可以在 UWP 中实现(如果应用程序已最小化或自动隐藏在其他应用程序后面,则将应用程序置于屏幕前面)?

任何帮助将非常感激。

提前致谢。

最佳答案

I have even tried to desktop extension with restricted capability "runFullTrust" to launch/bring the app in the foreground but still not succeeded

以上线程是正确的,我们可以获取当前应用程序的 entries然后调用 LaunchAsync 方法在桌面扩展中启动 UWP 应用。

IEnumerable<AppListEntry> appListEntries = await Package.Current.GetAppListEntriesAsync();
await appListEntries.First().LaunchAsync();

有关更多详细信息,请研究 stefan 的博客UWP 中的全局热键注册

关于c# - 如何以编程方式将 UWP 应用程序从后台(最小化模式)带到前台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63592989/

相关文章:

C# 相当于 VB6 中的 ccDebug

C#:映射 IDataReader.GetTableSchema() 和 DbType 枚举?

c# - Fluent Validation 重载 (Less)GreaterThanOrEqualTo 方法不会呈现相同的结果

c# - 时间触发器不触发后台任务 UWP

registry - 在 uwp 中读/写注册表项文件

c# - Http隧道不适用于某些网站

c# - Windows.Security.Cryptography.CryptographicBuffer 中的方法生成的 IBuffer 对象是否具有安全功能?

uwp - 如何从 UWP DatePicker 控件获取值?

c# - UWP:是否可以创建自己的网络文件(类似于 Onedrive)?

c# - 如何在运行时更新中仅在需要时更新列表?