ItemsControl.ItemsSource MVVM performance

后端 未结 2 405
眼角桃花
眼角桃花 2020-12-29 17:22

I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel instances. Now once the large amount Model instances is loaded al

相关标签:
2条回答
  • 2020-12-29 17:47
    <ItemsControl IsAsync="True" ... />
    
    0 讨论(0)
  • 2020-12-29 17:48

    You can create a a class derived from ObservableCollection which allows you to temporarily suspend CollectionChanged events like this:

    public class SuspendableObservableCollection : ObservableCollection
    {
        private bool suspended;
    
        public bool Suspended 
        {
            get
            {
                return this.suspended;
            }
            set
            {
                this.suspended = value;
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(
                    NotifyCollectionChangedAction.Reset));
            }
        }
    
        protected override void OnCollectionChanged(
            NotifyCollectionChangedEventArgs args)
        {
           if (!Suspended)
           {
               base.OnCollectionChanged(args);
           }
        }
    }
    
    0 讨论(0)
提交回复
热议问题