gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 09:00:22 25 4
gpt4 key购买 nike

我已经尝试了很多选项,以编程方式将 UWP 应用程序从最小化模式带到前台(所有正在运行的应用程序的顶部),但根本没有成功:(,以下是我尝试执行相同操作的选项:-
1:代码:-
等待 Windows.System.Launcher.LaunchUriAsync(new Uri("yourprotocolhere://"));`
它启动但无法将其置于前台,但它使应用程序在任务栏中闪烁。
2个代码:-
protected 覆盖无效 OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com