views:

65

answers:

2

Hi All,

I want to scroll the listbox which is placed inside the srollviewer according to its selection.

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

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

But it giving null value.

A: 

Hope this helps:

if (listView.SelectedItem != null)
{
   listView.ScrollIntoView(listView.SelectedItem);
}
Eugene Cheverda
A: 

Try below code

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