How can a universal windows app have multiple independent windows (Like Microsoft's app “Photos”)?

后端 未结 3 999
执念已碎
执念已碎 2021-02-04 10:50

I do know how to open additional windows using TryShowAsStandaloneAsync. However, if the original window is closed - TryShowAsStandaloneAsync fails (Wh

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 11:31

    I'm not sure if you're using Dispatcher.RunAsync to create the view, i.e:

    async private void Button_Click(object sender, RoutedEventArgs e)
     {
     CoreApplicationView newView = CoreApplication.CreateNewView();
     int newViewId = 0;
    
    await newView.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
     {
     var frame = new Frame();
     frame.Navigate(typeof(MainPage), newViewId);
     Window.Current.Content = frame;
    
    // In Windows 10 UWP we need to activate our view first.
     // Let's do it now so that we can use TryShow...() and SwitchAsync().
     Window.Current.Activate();
    
    newViewId = ApplicationView.GetForCurrentView().Id;
     });
    
     bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
     }
    

    for more info, please refer to : https://daxsnippets.wordpress.com/2015/07/09/windows-10-create-views/

提交回复
热议问题