C#/XAML/WPF binding working partially, only displays first item in List -


i have should simple binding, problem i'm seeing instead of displaying 3 companies (company_list list, company contains company_id bind to), see window pop first company_id in company_list. have other bindings seem work fine, , in other cases see i've used itemsource instead of datacontext, when use "items collection must empty before using itemssource". i've searched extensively simple answer in stackoverflow, msdn , elsewhere, , have seen complex solutions haven't been able understand/apply.

when window appears, has:

companya

where should have:

companya
companyb
companyc

which content of company_list (yes, verified in debugger). suggestions appreciated! code , xaml follow.

    readmastercompanylist();  // populates a_state.company_list 3 companies     // display company list dialog     companyselect cs_window = new companyselect();     cs_window.companylistview.datacontext = a_state.company_list;     // fails: cs_window.companylistview.itemssource = a_state.company_list;     cs_window.show(); 

and xaml companyselect:

<grid>     <listview issynchronizedwithcurrentitem="true"        x:name="companylistview"        selectionmode="single" selectionchanged="companylistview_selectionchanged">         <listview.itemcontainerstyle>             <style targettype="{x:type listviewitem}">                 <setter property="height" value="30"/>             </style>         </listview.itemcontainerstyle>         <listviewitem content="{binding path=company_id}"></listviewitem>     </listview> </grid> 

first, set datacontext after cs_window.show().

second, listviewitem have child in listview's xaml why you're seeing one.

third, might work better (and more mvvm-ish) if define itemssource in xaml, this:

<listview itemssource="{binding path=company_list}" ...> 

that's after making a_state datacontext of listview's container or other ancestor element.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -