c# - Binding ObservableCollection take much time in fact the window take much time to be displayed -
i'm using mvvm light framework wpf , have datagrid contain customers loaded sqlite database, take time display window if 1 can me can dislpay window , load datagrid separately.i think window taking time because of datagrid binding.
public observablecollection<custumermodel> customerlist { { _customerlist = new observablecollection<custumermodel>(); ilist<custumermodel> listcustomer = remplirelistcustomer(); _customerlist = new observablecollection<custumermodel>(listcustomer); return _customerlist; }
the method remplirelistcustomer
private ilist<custumermodel> remplirelistcustomer() { ilist<custumermodel> listcustomer = new list<custumermodel>(); foreach (var c in _customerservice.getallcustomers()) { listcustomer.add((custumermodel)c); } return listcustomer; }
you load data async starting new task
in e.g. class' constructor.
public class yourclass { public yourclass() { taskex.run(() => { var listcustomer = remplirelistcustomer(); customerlist = new observablecollection<custumermodel>(listcustomer); }); } public observablecollection<custumermodel> customerlist { get; private set; } }
and maybe not have iterate on customers returned service using foreach
, return collection _customerservice.getallcustomers()
?
Comments
Post a Comment