2014-11-04 78 views
2

因此,我正在基於音樂混洗的Windows Phone項目工作。我有一個頁面顯示隊列中的歌曲,代碼文件包含List<>,它將所有歌曲添加到列表中,但此任務需要更多時間。xaml頁面在windows phone中加載後如何完成任務

當我點擊一個按鈕導航(或顯示隊列)頁面我的應用程序仍然保持相同的頁面4-5秒。

我想如何在加載頁面後運行的xaml.cs文件中創建一些代碼。

當頁面加載後,我會顯示Progress Indicator,當所有數據完全在列表<>元素中時,我會顯示一首歌曲。

我的代碼:

private void Event() 
{ 
     currentQueueData = MediaPlayer.Queue; 
     List<QueueData> boundedQueueData = new List<QueueData>(); 

     SetProIndicator(true); 
     SystemTray.ProgressIndicator.Text = "Loading..."; 

     if (currentQueueData.Count != 0) 
     { 
      for (int i = currentQueueData.ActiveSongIndex, k = 0; i < totalqueueCount; i++) 
      { 
       loadedqueueSongs[k] = currentQueueData[i]; 
       boundedQueueData.Add(new QueueData() 
       { 
        queueSongIndex = k++, 
        queueSongName = currentQueueData[i].Name, 
        queueSongAlbum = currentQueueData[i].Album.Name + ",", 
        queueSongArtist = " " + currentQueueData[i].Artist.Name, 
       }); 
      } 
      queueList.ItemsSource = boundedQueueData; 
      SetProIndicator(false); 
      //queueList.Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); 
     } 
     else 
     { 
      boundedQueueData.Add(new QueueData() 
      { 
       queueSongIndex = 0, 
       queueSongName = "Currently Queue Is Empty", 
       queueSongAlbum = "", 
       queueSongArtist = "", 
      }); 
      queueList.ItemsSource = boundedQueueData; 
     } 
    } 
  • 如果可能的話,經過MyPage.xaml頁面事件()函數加載加載?
+0

void Event方法位於哪裏?誰需要它? – 2014-11-04 13:32:55

+0

在構造函數中 – VKC 2014-11-04 14:23:22

回答

2

繼評論問題後,一個可能的答案是訂閱頁面的Loaded事件並從那裏調用Event方法。

真正簡單的例子:

public MyPage() 
{ 
    this.Loaded += PageLoaded; 
} 

void PageLoaded(object sender, RoutedEventArgs e) 
{ 
    this.Event(); 
} 

所以我們所做的就是suscribe,在頁面的構造函數加載的事件。到頁面加載時,您將能夠從回調中調用您的Event方法。

相關問題