c# - Is there a better way to get lists to load without using ObservableCollection? -


we using telerik's radgridview display data, binding lists of business objects. of data loaded such

    [detaillist] // 20+ lists     public list<businessobject> businessobjects { get; } = new list<businessobject>();      private void filldetail(objectcontaininglotsofinfo object)     {         try         {             this.businessobjects.addrange(object.businessobjects.linq);             // linq sort of filter or selectmany statement.              this.refreshlists();         }         catch (exception exception)         {             trace.writeline(exception);             this.errormessage = exception.message;exception.message));         }     }      private void refreshlists()     {         var properties = this.gettype().getproperties().where(prop => prop.isdefined(typeof(detaillist), false));          foreach (propertyinfo item in properties)         {             trace.writeline($"refreshing detaillist.{item.name} property {this.identifier}");             this.raisepropertychanged(item.name);         }     } 

the application uses async start, , fill method called once data loaded retriever in task. however, user can navigate grids located (using ui thread) before data comes api. if grids views initialize before fill data method called grids stay empty, forever. if fill data called grids load fine. now, made lists observablecollections, , referenced microsoft.practices.prism use it's definition addrange, , worked fine when went grids before data loaded. once data loaded in won't changing in way, no adding or removing rows, , there performance hit using many observablecollections. there better way this? there way make raisepropertychanged it's job when data loaded?

edit definition of detaillist given below

public class detaillistattribute: attribute { } 

let's have list<poco> property named foo. implement conventional inpc stuff in it. bind usual itemssource somewhere. when async method finishes getting data, assign new list<poco> foo:

foo = pocofromwherever.tolist(); 

the foo setter raises propertychanged. you're fine. can thread without having invoke ui thread, too.

i'd recommend using readonlycollection<poco> instead of list<poco>, forestall potential misunderstandings fact collection can replaced, not modified.

foo = new readonlycollection<poco>(pocofromwherever.tolist()); 

i've been using pattern type of thing in wpf years. no need clever.

you might want make setter private, depending on requirements.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -