c# - ListView DataBindig using MVVM (WPF, ListView, Binding) -
i have model called listviewmodel 1 method:
namespace layoutmvvm.viewmodels { public class listviewmodel { public void getdata() { testviewclassdatacontext tv = new testviewclassdatacontext(); list<test_view> tvq = (from tt in tv.test_views select tt).tolist(); } } }
into usercontrol called listview want result model , bind list:
listview.xaml:
<usercontrol .....> <grid background="crimson"> <listview width="230" height="250" name="lvmylist"> <listview.view> <gridview> <gridviewcolumn header="firstname" width="90" displaymemberbinding="{binding firstname}" /> <gridviewcolumn header="lastname" width="90" displaymemberbinding="{binding lastname}" /> <gridviewcolumn header="type" width="50" displaymemberbinding="{binding type}" /> </gridview> </listview.view> </listview> </grid> </usercontrol>
listview.cs
namespace layoutmvvm.views { public partial class listview : usercontrol { public listview() { initializecomponent(); listviewmodel lvm = new listviewmodel(); lvmylist.itemssource = lvm.getdata(); //error } } }
i'm starting wpf , don't know how correclty bind data.
probably should change method follows, method return actual results,
public list<test_view> getdata() { testviewclassdatacontext tv = new testviewclassdatacontext(); list<test_view> tvq = (from tt in tv.test_views select tt).tolist(); return tvq; }
Comments
Post a Comment