2017-02-20 9 views
0

UWPデスクトップアプリケーションでは、特定のモニタでアプリケーションを強制的に開く方法がありますか? (私の場合、私はノートパソコンに接続されたラップトップや余分な画面を持っているので、私はコードで起動画面を指定したい)UWPアプリケーションの起動モニタを指定してください

私はWinFormsの中に次のコードを使用:どのように

Screen[] screens = Screen.AllScreens; 

if (Screen.AllScreens.Length == 1) 
      { 
       Application.Run(new frmMain()); 
      } 
else 
{ 
    //select largest monitor and set new monitor 
    Rectangle bounds = screens[LargestScreen].Bounds; 
    frm.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height); 
    frm.StartPosition = FormStartPosition.Manual; 

    Application.Run(frm); 
} 

任意のアイデアを上記のUWPアプリケーションを実装しますか?

答えて

0

アプリのmultiple viewsを作成し、方法StartProjectingAsyncProjectionManagerクラスを使用して、別の画面にセカンダリビューを表示できるようにする必要があります。 OnLaunchedメソッドでこれを行うことができますし、アプリケーションが起動すると、セカンダリビューが必要な画面に表示されます。

protected override async void OnLaunched(LaunchActivatedEventArgs e) 
{ 
    if (System.Diagnostics.Debugger.IsAttached) 
    { 
     this.DebugSettings.EnableFrameRateCounter = true; 
    } 
    Frame rootFrame = Window.Current.Content as Frame; 
    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 (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 
     { 
      //TODO: Load state from previously suspended application 
     } 
     // Place the frame in the current Window 
     Window.Current.Content = rootFrame; 
    } 
    ///Get all the screens. 
    String projectorSelectorQuery = ProjectionManager.GetDeviceSelector(); 
    var outputDevices = await DeviceInformation.FindAllAsync(projectorSelectorQuery); 
    //if(outputDevices.Count==1) 
    //{ 

    //} 
    int thisViewId; 
    int newViewId = 0; 
    ///Choose one screen for display . 
    DeviceInformation showDevice = outputDevices[1]; 
    thisViewId = ApplicationView.GetForCurrentView().Id; 
    if (e.PrelaunchActivated == false) 
    { 
     if (rootFrame.Content == null) 
     { 
     }   
     Window.Current.Activate(); 
    } 
    ///Create a new view 
    await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() => 
    { 
     Frame frame = new Frame(); 
     frame.Navigate(typeof(MainPage), null); 
     Window.Current.Content = frame;   
     Window.Current.Activate(); 
     newViewId = ApplicationView.GetForCurrentView().Id; 
    }); 
    await ProjectionManager.StartProjectingAsync(newViewId, thisViewId, showDevice); 

} 

は、しかし、それはStartProjectingAsync方法は、新しいビューIDを必要とするため、直接他の画面に表示することができない最初のビューのように思えます。あなたのアプリが起動したときに作成される最初のビューは、メインビューと呼ばれます。このビューは作成しません。それはアプリによって作成されています。メインビューのスレッドはアプリのマネージャーとして機能し、すべてのアプリのアクティベーションイベントはこのスレッドで配信されます。メインビューを閉じることができないため、最初のメインビューは最初の画面に残ります。

詳細はProjection official sampleを参照してください。

+0

ありがとう、私の質問に答えました。 – user3385105

関連する問題