2014-04-18 32 views
0

我想在我的應用程序中使用輸入選定的索引來滾動列表框(水平滾動)。我在MSDN上找到了這個ScrollIntoView方法,但它不起作用,並且在ListBox Class頁面上它已經被寫入與WP 7.0,7.1兼容。所以,這是我的代碼快照...列表框水平滾動方法C#WP 8.0

scrolling.ScrollIntoView(scrolling.Items[20]); 

其中滾動是我的ListBox和20項是一個我想選擇和可視化。 PS:我已經嘗試使用selectedIndex方式,但它仍然無法使用!

這是我的ListBox(放置在佈局網格中)的一個xaml,它具有引用到App.xaml文檔中編寫的模板的引用。

<ListBox x:Name="scrolling" Grid.Column="0" ScrollViewer.ManipulationMode ="Control" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Visible"> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
    </ListBox> 

編輯:我發現通過按鈕調用函數可以使所有的東西都可以工作,但是如何在開始時初始化所有東西?

回答

0

我在我的解決方案首先更新UI使用後被稱爲ScrollIntoView正常工作:

scrolling.UpdateLayout(); 
scrolling.ScrollIntoView(scrolling.Items[20]);