Arrow keys don't work after programmatically setting ListView.SelectedItem

前端 未结 9 1770
感情败类
感情败类 2020-12-16 02:34

I have a WPF ListView control, ItemsSource is set to an ICollectionView created this way:

var collectionView = 
  System.Windows.Data.CollectionViewSource.Ge         


        
9条回答
  •  长情又很酷
    2020-12-16 03:10

    Cheeso, in your previous answer you said:

    But there's also a second problem with that - it doesn't work right after setting the SelectedItem. ItemContainerGenerator.ContainerFromItem() always seems to return null.

    An easy solution to that is to not set SelectedItem at all. This will automatically happen when you focus the element. So just calling the following line will do:

    ((UIElement)this.listView1.ItemContainerGenerator.ContainerFromItem(thing)).Focus();
    

提交回复
热议问题