Select item listbox wpf

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:
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.

Regards

What I have tried:

I tried:

lbxArtikel.UpdateLayout[]; var lbxItem = [ListBoxItem]lbxArtikel .ItemContainerGenerator .ContainerFromItem[lbxArtikel.SelectedItem]; lbxItem.Focus[];But this selected only the first entry.
lbxArtikel.ScrollIntoView[lbxArtikel.SelectedItem]
thx to U.G.Leander!

Add your solution here

B I U S small BIG code var < > & link [^] encode untab case indent outdent

Preview 0

Existing Members

...or Join us

Download, Vote, Comment, Publish.

Your Email
This email is in use. Do you need your password?
Optional Password
When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.

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

Video liên quan

Chủ Đề