c# - Observable sub property String to listbox binding -


sorry what's simple question.

i have class appointment has various string properties.

i have observable collection of them in view model, whenever bind of properties listbox returns every character first entry having it's own row

sorry don't have code on hand, sum up

сlass appointment {     public appointment(string ыubject)     {          subject = subject;     }      public string subject { get; set; } }  class appointments {      public appointments()     {          listofappointments = new observablecollection<appointment>();         listofappointments.add(new listofappointments("example"));     }      public observablecollection<appointment> listofappointments { get; set; } } 

in xaml:

<listbox datacontext="{staticresource appointementviewmodel, path=listofappointments}" itemsource="{binding subject }" /> 

hoping that correct. results listbox shows is

e x m p l e 

i'm pretty clue less @ moment , not updating information after initial fetch not have inotifyproperty implemented

please note data being loaded correctly quick example replicate.

also if use linq in backend query it returns correct results actual implementation has more 1 field cumbersome workaround. ideas?

the listbox itemssource should listofappointments , in datatemplate can bind subject property

<listbox datacontext="{staticresource appointementviewmodel}" itemsource="{binding listofappointments}" itemtemplate="{staticresource mytemplate}"/>  <datatemplate x:key="mytemplate">    <textblock text="{binding subject}" /> </datatemplate> 

in code sample given in question, listofappoinments given datacontext of listbox , subject itemssource. listbox taking subject property first object in listofappoinments itemssource. string split , assigned each listboxitem.

in above code, have given listofappoinments itemssource. each appointment object taken list , assigned listboxitems. since have bound subject textblock in datatemplate, displayed.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -