2017-10-08 131 views
0

我正在閱讀槽UWP的文檔,我卡住了一下。頁面導航事件

我有幾個頁面連接到WCF服務獲取它的一些信息,其中幾個下載圖片,並需要幾秒鐘加載。

當我嘗試使用

this.Frame.Navigate(typeof(page)); 

我就會陷入死鎖狀態一切,而新的頁面加載,我試圖把對凍結所以我決定來實現加載屏幕但同時它們的加載頁面加載事件在其他頁面上,但這並沒有什麼幫助,因爲它仍然鎖定在最後一頁。

有沒有人知道我需要調用this.Frame.Navigate()時需要調用的正確事件,以便在新幀加載時初始化我的加載控件?

+0

你嘗試過'OnNavigatedTo'事件嗎? –

+0

是的,它確實進入了內部,但也沒有幫助,我也嘗試過Navigate,OnNavigateFrom大多數。 –

+0

「加載屏幕」是否會在轉到實際頁面之前導航的頁面? –

回答

0
  1. 導航到加載屏幕

    this.Frame.Navigate(typeof(LoadingScreen)); 
    
  2. 在LoadingScreen OnNavigatedTo事件 「圖片下載」

    protected override async void OnNavigatedTo(NavigationEventArgs e) 
    { 
        await DownloadPictures(); 
        //After downloading, navigate to the next page 
        this.Frame.Navigate(typeof(page)); 
    } 
    
+0

您的回答是正確的,但我不得不將它放在頁面加載並隱藏控件,因爲進度控件在導航時未初始化 –

0

嘗試推出一個單獨的窗口中的視圖這樣

 try 
     { 
      CoreApplicationView Nv= CoreApplication.CreateNewView(); 
      var z = CoreApplication.MainView; 

      int id= 0; 
      await 
    Nv.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => 
      { 
       Frame frame = new Frame(); 
       frame.Navigate(typeof(page)); 

       Window.Current.Content = frame; 
       // You have to activate the window in order to show it later. 
       Window.Current.Activate(); 




       id= ApplicationView.GetForCurrentView().Id; 
      }); 
      bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id); 


     } 
     catch (Exception eee) 
     { 
      Windows.UI.Popups.MessageDialog errorBox = 
       new Windows.UI.Popups.MessageDialog("Couldn't Create New 
      Window: " + eee.Message); 
      await errorBox.ShowAsync(); 


     } 
+0

我的當前功能已經實現了此方法,但是我想從當前框架中找到一種方法來打開一個新窗口。 –

+0

@KristiforMilchev你的問題帖子太抽象了,並沒有提供足夠的信息給任何人玩。 –

+0

沒有什麼抽象的東西,我需要一個事件,在兩幀之間的過渡時異步文件,就像你的答案,但避免打開一個新的框架。 –