2010-07-20 193 views
1

我想滾動根據其選擇放置在srollviewer內的列表框。如何從列表框中獲取列表框項目wpf

ListBoxItem item = (ListBoxItem)(lbTrack.ItemContainerGenerator.ContainerFromItem(lbTrack.Items.CurrentItem)); 

     // ListBoxItem item = (ListBoxItem)(lbTrack.ItemContainerGenerator.ContainerFromItem(lbTrack.SelectedItem)); 
     if (item != null) 
     { 
      item.BringIntoView(); 
     } 

但它給予空值。

回答

1

希望這有助於:下面的代碼

if (listView.SelectedItem != null) 
{ 
    listView.ScrollIntoView(listView.SelectedItem); 
} 
0

嘗試

Dispatcher.CurrentDispatcher.BeginInvoke((ThreadStart)delegate 
    { 
     item.BringToView(); 
    }, DispatcherPriority.Normal, null);