2014-03-27 22 views
0

我有問題滾動到第一頁加載事件中的列表框的選定索引。第一次加載頁面時,它將無法滾動到所選索引,而所選索引被更改並突出顯示。當我導航到另一個頁面並返回到此頁面時,它將滾動到選定的索引。我不明白爲什麼它不能在第一頁加載時滾動。如何滾動到wp8列表框的SelectedIndex

void MainPage_Loaded(object sender, RoutedEventArgs e) 
{ 
    try 
    { 
     ApplicationBarIconButton btn = (ApplicationBarIconButton)ApplicationBar.Buttons[1]; 
     if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState) 
     { 
     btn.IconUri = new Uri("/Images/pause.png", UriKind.Relative); 
     BackgroundAudioPlayer player = BackgroundAudioPlayer.Instance; 
     if (player.Track != null) 
     { 
      currentChapter = ds.getChapter(Convert.ToByte(player.Track.Artist.Split(DataSource.TRACKARTISTDELIMTER)[0])); 
      lsbReadingChapter.ItemsSource = ds.getArabicTextWithTranslation(currentChapter); 

      //Get Position and Start timer 
      fillRecitation(); 
      double position = player.Position.TotalSeconds; 
      setSelectedIndex(position); 
      recitationTimer.Start(); 
     } 
     } 
     else 
     { 
     lsbReadingChapter.ItemsSource = ds.getArabicTextWithTranslation(currentChapter); 
     recitationTimer.Stop(); 
     btn.IconUri = new Uri("/Images/play.png", UriKind.Relative); 
     scrollIntoSelectedItem(Convert.ToByte(App.Recent.AyaID)); 

     } 

     txtTitle.Text = HCI.convertToArabicIndicString(currentChapter.ChapterID) + " - " + currentChapter.SuraName + " - " + HCI.convertToArabicIndicString(currentChapter.Ayas); 

     if (currentChapter != null) 
     { 
     if (ds.chapterAvailable(currentChapter)) 
      txtAvailable.Text = "available"; 
     else 
      txtAvailable.Text = string.Empty; 
     } 

     if (lsbReadingChapter.SelectedIndex != -1) 
     scrollIntoSelectedItem(lsbReadingChapter.SelectedIndex); //scroll to index 
    } 
    catch (Exception) { } 
} 

void scrollIntoSelectedItem(int index) 
{ 
    lsbReadingChapter.SelectedIndex = lsbReadingChapter.Items.Count - 1; 
    lsbReadingChapter.UpdateLayout(); 
    lsbReadingChapter.ScrollIntoView(lsbReadingChapter.SelectedIndex); 

    lsbReadingChapter.SelectedIndex = index; 
    lsbReadingChapter.UpdateLayout(); 
    lsbReadingChapter.ScrollIntoView(lsbReadingChapter.SelectedIndex); 

} 

這不適用於第1頁加載事件。我不明白是什麼導致它不滾動?

謝謝!

回答

0

在您的頁面加載中使用此功能。

this.Page.MaintainScrollPositionOnPostBack = true; 
+0

我們在windows phone 8中有這樣的屬性嗎? – ARH

+0

那麼Windows Phone 8沒有列在http://msdn.microsoft.com/en-us/library/system.web.ui.page.maintainscrollpositiononpostback(v=vs.110).aspx平臺上......所以也許不,但必須有類似的東西。 – Alok

+0

您可以通過在document.documentElement.scrollTop中填充隱藏字段然後在頁面加載上滾動到該位置來解決此問題。 – Alok