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));
}
}
}
- ui selection lost: when new data arrived datalist cleared - ui selection lost.
- perfomance: each datalist.add(x) call "updates" observablecollection , forces ui refresh. want update entire table , after refresh ui. current application takes 15% of cpu
- 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"...
- mvvm approach - create consoledataviewmodel , in overviewviewmodel store instances of consoledataviewmodel instead of consoledata. don't know how implement consoledataviewmodel. can read more that?
please choose first one:
simple example:
http://www.codeproject.com/kb/wpf/stepbystepguidetomvvm.aspx
more complex one:
http://www.codeproject.com/kb/wpf/mvvmepisode1.aspx
http://www.codeproject.com/kb/wpf/mvvmepisode2.aspx
http://www.codeproject.com/kb/wpf/mvvmepisode3.aspx
Silverlight > MVVM / ViewModel Pattern with Silverlight
Comments
Post a Comment