c# - Binding properties of object instances from ObservableCollection to ListView -
i need bind observablecollection<t> property of view model view. view model class.
namespace { public class compositeviewmodel { public compositeviewmodel { ilist<mytype> temp = new list<mytype>(); (int = 0; < 10; i++) { mytype entry = new mytype(); entry.id = 1; entry.name = "foo"; temp.add(entry); } collectionb = new observablecollection<mytype>(temp); } public observablecollection<mytype> collectiona { get; private set; } public observablecollection<mytype> collectionb { get; private set; } } public class mytype { public string name { get; set; } public int id { get; set; } } } and xaml user control.
<usercontrol x:class="product.views.compositeview" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:models="clr-namespace:product.viewmodels" mc:ignorable="d"> <listview itemssource="{binding collectionb}"> <listview.view> <gridview> <gridviewcolumn header="id" width="300" displaymemberbinding="{binding id}"/> <gridviewcolumn header="name" width="300" displaymemberbinding="{binding name}"/> </gridview> </listview.view> </listview> <usercontrol.datacontext> <models:compositeviewmodel/> </usercontrol.datacontext> </usercontrol> when application run, listview displays fully-qualified name of mytype class. how display value of id , name fields instead?
edit: added screenshot of output see.
edited abin mathew show output.
i feel stupid now. turns out had following snippet declared in styles.
<style targettype="{x:type listviewitem}"> <setter property="background" value="transparent"/> <setter property="template"> <setter.value> <controltemplate targettype="{x:type listviewitem}"> <contentpresenter/> </controltemplate> </setter.value> </setter> </style> it needed listview instance , had put in app resources temporarily. moving instance's own style definitions fixed issue.


Comments
Post a Comment