原文地址:http://stackoverflow.com/questions/16866309/listbox-scroll-into-view-with-mvvm

public class ScrollingListBox : ListBox
    {
        protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems!=null)//此处需要判空
            {
                int newItemCount = e.NewItems.Count;

                if (newItemCount > 0)
                    this.ScrollIntoView(e.NewItems[newItemCount - 1]);

                base.OnItemsChanged(e);
            }            
        }
    }
<controls:ScrollingListBox ItemsSource="{Binding ChatList}" Background="WhiteSmoke"  Style="{StaticResource ChatListBoxStyle}"/>

 

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2021-11-16
  • 2021-08-01
  • 2021-12-13
  • 2021-09-04
  • 2022-01-09
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2021-12-18
  • 2022-01-14
  • 2022-01-25
  • 2022-12-23
相关资源
相似解决方案