2017-10-03 21 views
0

私のアプリケーションにはMVVMモデルに従っています。コレクションをフィルタリングする入力として機能するテキストボックスがあります。ラムダ式を使ってobservablecollectionフィルターを理解しましたが、collectionviewsourceメソッドを理解できませんでした。私はどのようにこれを使用してcollectionviewsourceメソッドを実装できますか?ここでCollectionviewsourceフィルタメソッド

は私のviewmodelクラスです:

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'の近くにエラーが発生しました。定義は存在しません。 Intellisenseをチェックすると、Equals、Hashcode、GetType、ToStringの4つのオプションしか表示されません。エンティティのプロパティは表示されません –

+0

申し訳ありませんが、entity.MU_Identifierである必要があります。回答が編集されました。 – mm8

+0

はい、これはうまくいきました.XAMLではバインドするのにALLCRSPを使うべきですか? –

関連する問題