How to store List of objects in ViewModel to display them in DataGrid?


the task pretty simple , i'm sure absolutely general - need display list of objects in datagrid.

in more details:

i have collection of "consoledata" objects (from trading software). each consoledata has

  • read-only static fields (ticker)
  • read-only dinamic fiels update every second (price)
  • mutable static fields - strategy parameters. numbers static can changed user directly datagrid via command (stop loss)

my implementation:

    public class overviewviewmodel
{
public observablecollection<consoledata> datalist { get; set; }

public overviewviewmodel(iwcfmodel model)
{
this.datalist = new observablecollection<consoledata>();
model.dataarrived += new action<list<consoledata>>(model_dataarrived);
}

private void model_dataarrived(list<consoledata> datalist)
{
            // every time receive fresh table - not changes, entire table
datalist.clear();
datalist.foreach(x => datalist.add(x));
}

}

}
there several problems implementation:
  1. ui selection lost: when new data arrived datalist cleared - ui selection lost.
  2. perfomance: each datalist.add(x) call "updates" observablecollection , forces ui refresh. want update entire table , after refresh ui. current application takes 15% of cpu
so far know 2 solutions problem:
  1. make consoledata implement inotifypropertychanged, instead of "replacing consoledata" in viewmodel "update consoledata" in viewmodel. think solve problem 1 not problem 2. think it's not "mvvm-complained"...
  2. mvvm approach - create consoledataviewmodel , in overviewviewmodel store instances of consoledataviewmodel instead of consoledata. don't know how implement consoledataviewmodel. can read more that?
which solution should select 1 or 2? read more solution 2? can suggest better solution? 



Silverlight  >  MVVM / ViewModel Pattern with Silverlight



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........