c# - Filter and update a ReadOnlyObservableCollection -
c# - Filter and update a ReadOnlyObservableCollection -
i have ordinary observablecollection carries billdetailsviewmodel. need expose collection create bindable view, not alterable outside vm. here comes readonlyobservablecollection: pretty handy, pretty simple. need ability filter results shown. i'm doing dinamically creating new readonlyobscoll every time filters list changes, , updating binding listview itemssource, way:
this.filteredbills = new readonlyobservablecollection<billdetailsviewmodel>( new observablecollection<billdetailsviewmodel>( this.bills.where(b => this.filter(b))));
the problem that, of course, must manually refresh binding on readonlyobscoll every time create edit collection or item of collection.
is there improve way this. or improve if move filtering , sorting logic ui layer using extended list control?
thank in advance!
when dealing filtering, it's thought have 2 collections, or 2 sources.
1st original source (it may not collection @ naturally, example)
2nd collection finishes on ui
via vm
. collection can changed, ui
filtered. reset filter, reload 2nd collection 1st.
according documentation of readonlyobservablecollection
if changes made underlying collection, readonlyobservablecollection reflects changes.
so under hood may operate on real observablecollection
have.
in way avoid creating new objects every time, , good:
1) because messing binding
2) because pump program's memory.
c# .net sorting mvvm filtering
Comments
Post a Comment