WPF - reset ListBox scroll position when ItemsSource changes

前端 未结 5 2408
有刺的猬
有刺的猬 2021-02-18 23:41

I currently have a ListBox whose ItemsSource collection is bound to a property on my viewmodel, of type IEnumerable. When that preoprty\'s reference changes, the ListBox update

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 00:09

    Try this:

    if (listBox.Items.Count > 0) {
        listBox.ScrollIntoView(listBox.Items[0]); 
    }
    

提交回复
热议问题