tags:

views:

1184

answers:

1

Hello,

I have a Listbox that is filled with 30,000 elements

<ListBox Name="lbWordlist" 
             Grid.Row="1" Margin="10"
             ItemsSource="{Binding Source={StaticResource WordListViewSource}}" 
             SelectedItem="{Binding Source={StaticResource MainViewModel}, Path=SelectedArticle}"
             IsSynchronizedWithCurrentItem="True"
             SelectionChanged="lbWordlist_SelectionChanged" />

I'm tracking history of user clicking items

I have 2 buttons Prev. and Next, these buttons allow user to go back and forward in history.

Prev. and Next button modify SelectedItem property of ListBox

The problem comes up, if user selects random items from ListBox that are very apart from each other (for example user selected some items on top of the list and few items in the bottom of the list).

Prev. and Next button change SelectedItem property, but ListBox is not synced with scroll, selected item is not highlighted and most of the times is not visible to user, as it's outside of ListBox's visible items area.

Is there any way to make ListBox correctly show currently selected item?

Thank You.

+4  A: 
_listBox.ScrollIntoView(_listBox.SelectedItem);

HTH, Kent

Kent Boogaart
This helped, thank you :)
Daniil Harik
You're welcome. If it answered your question, you can mark it as the answer by checking the box alongside my answer.
Kent Boogaart