Click here to Skip to main content
15,796,102 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF ListBox with the ItemsSource bound to a ViewModels list of MyObjects (products). This works fine, the lisbox will be filled with products from Database. Unfortunatly there are over 4.000 entries in the DB. When the user navigates to the listbox, a specific product entry should be selected and focused, just like when the user clicks a specific entry with the mouse. Is the a simple way in WPF to solve this?
Binding the selected item with XAML like this works:
<ListBox SelectedItem="{Binding SelectedArtikel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

but the selected item is somewhere deep in the list. The selected item is marked as selected but not in sight, you have to scroll down manually.


What I have tried:

I tried:
var lbxItem = (ListBoxItem)lbxArtikel
But this selected only the first entry.
Updated 20-May-22 12:29pm
U. G. Leander 30-Mar-16 8:35am    
You could try lbxArtikel.ScrollIntoView(lbxArtikel.SelectedItem),
assuming lbxArtikel is your ListBox and then set the focus on the item.
susad 30-Mar-16 8:43am    
Thank You!! That's it!
U. G. Leander 30-Mar-16 10:03am    
You're welcome! Could you please mark the question as solved, so that it doesn't appear in the "unanswered"-category?

1 solution


thx to U.G.Leander!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900