2017-01-02 43 views
0

在我的應用程序中,我調用LaunchUriAsync方法時添加了邏輯以使應用程序處於前臺。 但我可以找到各種選項將控件放在頁面的前面,但我想在啓動時關注頁面。 請分享建議,如果你有。關注UWP中的主頁

+0

歡迎來到Stack Overflow!你可以先參加[遊覽]並學習[問]一個很好的問題,然後創建一個[mcve]。這使我們更容易幫助你。 – Katie

回答

0

在我看來,一旦您使用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(); 
} 
+0

其實,我已經嘗試過,但應用程序圖標仍然只閃爍,但它沒有將應用程序放在前臺。 – Priya

+0

@Priya您能否向我提供一個[最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve)? –