2017-12-12 23 views
0

コレクションビューソースを使用してアイテムをフィルタ、グループ化、ソートしていますが、ソース内のコンポーネントを削除または追加するとビューが更新されません。ソースが変更されたときにCollectionViewSourceが更新されない

源:

public ObservableCollection<Component> Components 
{ 
    get 
    { 
     return mComponents; 
    } 
} 

CollectionViewSource:

this.ComponentCollection.Source = this.Components; 
this.ComponentCollection.View.Refresh(); 

これ:

this.ComponentCollection = new CollectionViewSource(); 
this.ComponentCollection.Source = this.Components; 
this.ComponentCollection.GroupDescriptions.Clear(); 
this.ComponentCollection.GroupDescriptions.Add(new PropertyGroupDescription("Template.ComponentType")); 
this.ComponentCollection.SortDescriptions.Clear(); 
this.ComponentCollection.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending)); 
this.ComponentCollection.Filter += this.Filter; 

ビューからコンポーネントを追加または削除する唯一の方法は、ソースを再適用することですCollectionViewSourceを使用する方法です:

ItemsSource="{Binding Path=ComponentTemplateCollection.View.Groups}" 

私はコレクションのフィルタリングに問題はありませんが、これはうまくいきますが、削除するか、コンポーネントから何かを追加する場合は、this.Components.Remove(x)は何もしません。

+0

答えがあなたを助けた場合は、回答としてマークしてください。 –

答えて

0

何とかmComponentsがコレクションビューソースの問題であることを明らかに上書きしました。しかし、物件を上げることは何もしなかった。私はまた、ディスパッチャーで追加と削除を呼び出す必要がありました。

関連する問題