data binding - WPF Markup Not Seeing Type in a Different Namespace -
i'm sure noob question wpf databinding experience, noob. apologies ahead of time:
i'm trying bind collection of objects (ienumerable) listbox shown below. problem when logentry type in same namespace (activitylog) "codebehind", can see object's properties rendered in listbox. however; when logentry type in different namespace (activitylog.classes) nothing shows in listbox.
i've tried adding activitylog.classes namespace in xaml markup (xmlns:local="clr-namespace:activitylog.classes"), i'm sure there's additional step i'm missing.
please help.
namespace activitylog { public partial class logpage : window { public logpage() { initializecomponent(); list<logentry> lelist = new list<logentry>() { new logentry() { startdate=datetime.parse("2011-05-10 9:58:00"), activitydescription="three" + environment.newline}, new logentry() { startdate=datetime.parse("2011-05-10 9:58:00"), activitydescription="four" + environment.newline}}; this.lstbox.itemssource = lelist; } } public class logentry { public datetime startdate { get; set; } public string activitydescription { get; set; } } }
<window x:class="activitylog.logpage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:activitylog.classes" title="logpage" height="564" width="414" > <grid> <listbox width="361" margin="20,50,0,0" itemssource="{binding}" name="lstbox" height="429" verticalalignment="top" horizontalalignment="left"> <listbox.itemtemplate> <datatemplate> <stackpanel> <textblock text="{binding path=startdate}"/> <textblock text="{binding path=activitydescription}" /> </stackpanel> </datatemplate> </listbox.itemtemplate> </listbox> </grid> </window>
you setting itemsource of listbox twice. once in codebehind
this.lstbox.itemssource = lelist;
then again in xaml
itemssource="{binding}"
in example provided codebehind version correct , should remove xaml version.
your xaml version binding datacontext property of logpage, if want hook way codebehind should setting
this.datacontext = lelist;
Comments
Post a Comment