How to focus on ListviewItem in WPF?

In ListBoxmy Ten Point paragraph application, the user can see five elements at a time. Sometimes I select elements from the code and focus settings.

Element selection and focusing work fine when elements are visible on Form, but for other invisible elements I cannot set focus (NOTE: after selection, it is visible to the user).

Can anybody help me?

var item = _listView.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem;

if (item != null)
{
   item.Focus();
}
+3
source share
1 answer

You tried:

_listView.SelectedIndex = index;

var item = _listView.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem;
if (item != null)
{
   item.Focus();
}
0
source

Source: https://habr.com/ru/post/1744522/


All Articles