2017-10-03 6 views
0

I 내 ​​응용 프로그램에 MVVM 모델을 따르십시오. 컬렉션 필터링을위한 입력 역할을하는 텍스트 상자가 있습니다. 나는 observablecollection 필터를 람다 표현식을 사용하여 이해하지만 collectionviewsource 메소드를 이해할 수 없었다. 어떻게 이것을 사용하여 collectionviewsource 메서드를 구현할 수 있습니다. 여기 Collectionviewsource 필터 메서드

내 뷰 모델 클래스입니다 :

private ObservableCollection<SPFetchCREntity> _CRmappings2 = new ObservableCollection<SPFetchCREntity>(); 
public ObservableCollection<SPFetchCREntity> CRmappings2 
{ 
    get { return _CRmappings2; } 
    set 
    { 
     _CRmappings2 = value; 
     RaisePropertyChanged("CRmappings2"); 
    } 
} 

public ICollectionView AllCRSP 


{ get; private set;} 



public void UpdatePopList() 
{ 
    CRmappings2 = new ObservableCollection<SPFetchCREntity>(crentities.Where(p => p.MU_Identifier == selectmu.ToString()).ToList()); 
} 
+0

https://wpftutorial.net/DataViews.html – Mishka

+0

@Mishka 아주 좋은 그 링크, 고맙습니다 –

답변

1

ICollectionView에 결합 필터링이 하나

public void UpdatePopList() 
{ 
    CRmappings2 = new ObservableCollection<SPFetchCREntity>(crentities.ToList()); 
    AllCRSP = CollectionViewSource.GetDefaultView(CRmappings2); 
    AllCRSP.Filter = obj => 
    { 
     SPFetchCREntity entity = obj as SPFetchCREntity; 
     return entity != null && entity.MU_Identifier == selectmu.ToString(); 
    }; 
} 

private string _selectmu; 
public string Selectmu 
{ 
    get { return _selectmu; } 
    set { _selectmu = value; AllCRSP.Refresh(); } //<-- refresh the ICollectionView whenever the selectmu property gets set or when you want to refresh the filter 
} 
+0

'obj.MU_Identifier' 근처에서 오류가 발생했습니다. definiton은 존재하지 않습니다. intellisense를 체크했을 때 Equals, Hashcode, GetType, ToString과 같은 네 가지 옵션 만 보여주었습니다. 엔티티 속성이 표시되지 않습니다. –

+0

죄송합니다. 엔티티 .MU_Identifier 여야합니다. 답변이 수정되었습니다. – mm8

+0

예,이 작업과 XAML에서 나는 ALLCRSP를 사용하여 바인딩해야합니까? –