Implementing ICollectionViewLiveShaping

前端 未结 3 861
-上瘾入骨i
-上瘾入骨i 2021-02-05 14:36

How is ICollectionViewLiveShaping implemented for the purpose of filtering? Is it something like:

public ICollectionView WorkersEmployed { get; set;         


        
3条回答
  •  情书的邮戳
    2021-02-05 14:44

    All you need to do is add a property in LiveFilteringProperties for which you want the filter to call on property change and set IsLiveFiltering to true for your collection to enable live filtering.

    Make sure PropertyChanged event gets raised whenever EmployerID property changes i.e. your Worker class should implement INotifyPropertyChangedEvent.

    This will work then -

    public ICollectionViewLiveShaping WorkersEmployed { get; set; }
    
    ICollectionView workersCV = new CollectionViewSource
                             { Source = GameContainer.Game.Workers }.View;
    
    ApplyFilter(workersCV);
    
    WorkersEmployed = workersCV as ICollectionViewLiveShaping;
    if (WorkersEmployed.CanChangeLiveFiltering)
    {
        WorkersEmployed.LiveFilteringProperties.Add("EmployerID");
        WorkersEmployed.IsLiveFiltering = true;
    }
    

提交回复
热议问题