Wpf MVVM binding List<List> to datagrid -



Wpf MVVM binding List<List<string>> to datagrid -

i want bind property of model datagrid, can't have property in model model contains list list of strings rows count constant in list

public class viewmodelbase : inotifypropertychanged { public event propertychangedeventhandler propertychanged; [notifypropertychangedinvocator] protected virtual void onpropertychanged([callermembername] string propertyname = null) { propertychangedeventhandler handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } } public class testviewmodel : viewmodelbase { public testviewmodel() : this(new fileservice()) { } public testviewmodel(ifileservice fileservice) { var list = new list<list<string>>(); list.add(new list<string>() { "1", "2", "3" }); list.add(new list<string>() { "3", "4", "5" }); recodlistfromcsv = list; } private list<list<string>> _recodlistfromcsv; public list<list<string>> recodlistfromcsv { { homecoming _recodlistfromcsv; } set { if (_recodlistfromcsv != value) { _recodlistfromcsv = value; onpropertychanged("recodlistfromcsv"); } } } }

xaml

<window x:class="test.views.testview" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:viewmodel="clr-namespace:test.viewsmodel" title="pricelist" height="427" width="746"> <window.resources> <viewmodel:testviewmodelx:key="tm" /> </window.resources> <dockpanel lastchildfill="true" datacontext="{binding source={staticresource tm}}"> <datagrid autogeneratecolumns="true" itemssource="{binding recodlistfromcsv}"> </datagrid> </menu> </dockpanel> </window>

and ui show

what i'm doing wrong. how it?

each row item of datagrid type of list<string> auto generating column of datagrid generate public property of list<string> object(capacity,count)!. resolve instead of list<list<string>> using list<tuple<string,string,string>> if items number 3.

var list = new list<tuple<string,string,string>>(); list.add(new tuple<string,string,string>() { "1", "2", "3" }); list.add(new tuple<string,string,string>() { "3", "4", "5" }); recodlistfromcsv = list;

the stable solution create persistent class , create list of object class properly.

wpf binding

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -