【问题标题】:Give focus to the main page in UWP将焦点放在 UWP 中的主页上
【发布时间】:2017-01-03 10:33:15
【问题描述】:

在我的应用程序中,我需要添加逻辑,以便在调用 LaunchUriAsync 方法时将应用程序置于前端。 但是我可以找到各种选项来将控件放在页面的前面,但我想在启动时关注页面。 如果你有建议,请分享。

【问题讨论】:

标签: uwp


【解决方案1】:

在我看来,一旦你使用LaunchUriAsync 方法启动应用程序,应用程序的OnActivated 事件就会被触发。您可以在此处理程序方法中导航到 MainPage 并调用 Window.Current.Activate() 通过将应用程序窗口置于前台并将输入焦点设置为其来激活应用程序窗口。

protected override void OnActivated(IActivatedEventArgs args)
{
    base.OnActivated(args);
    if (args.Kind == ActivationKind.Protocol)
    {
        Frame rootFrame = Window.Current.Content as Frame;
        if (rootFrame == null)
        {
            rootFrame = new Frame();
            rootFrame.Navigate(typeof(MainPage));
            Window.Current.Content = rootFrame;
        }
    }
    Window.Current.Activate();
}

【讨论】:

猜你喜欢
  • 2013-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-24
  • 1970-01-01
  • 1970-01-01
  • 2017-02-24
  • 2020-07-04
相关资源
最近更新 更多