wpf - Use CollectionViewSource with TabControl -


i'm trying group , display items of observablecollection, using xaml code. works using simple collectionviewsource , listbox[1].

actually, prefer display group's content in tabcontrol. google led me following social.msdn article wich presents workaround display groups tabcontrol using code behind:

https://social.msdn.microsoft.com/forums/vstudio/en-us/e073f275-0826-4fca-b9da-e310ccf1713e/wpf-grouping?forum=wpf

however, i'm using mvvm , must rely on xaml only, can't work. actually, collectionviewsource populates groups (the tabcontrol shows correct tabitemheaders), clicking on of these tabitems freezes application. here's i've tried:

    <stackpanel x:key="modulselectinputparameterview">     <stackpanel.resources>         <collectionviewsource x:key="cvs" x:name="collectionviewsource" source="{binding referencedlmtitem.modulinputparametercollection }">             <collectionviewsource.groupdescriptions>                 <propertygroupdescription propertyname="category"/>             </collectionviewsource.groupdescriptions>         </collectionviewsource>     </stackpanel.resources>      <grid >         <tabcontrol itemssource="{binding source={staticresource cvs}, path=groups, mode=oneway}" datacontext="{binding source={staticresource cvs}, mode=oneway}">             <!-- first level -->             <tabcontrol.itemtemplate>                 <datatemplate>                     <textblock text="{binding name}"/>                 </datatemplate>             </tabcontrol.itemtemplate>             <tabcontrol.contenttemplate>                 <datatemplate>                     <listbox itemssource="{binding items}">                          second level                          <listbox.itemtemplate>                             <datatemplate>                                 <expander header="{binding name}">                                     <listbox itemssource="{binding items}">                                          item of collection                                          <listbox.itemtemplate>                                             <datatemplate>                                                 <stackpanel orientation="horizontal">                                                     <textblock text="{binding key}"/>                                                     <textblock text=" - "/>                                                     <textblock text="{binding value.comment}"/>                                                 </stackpanel>                                             </datatemplate>                                         </listbox.itemtemplate>                                     </listbox>                                 </expander>                             </datatemplate>                         </listbox.itemtemplate>                     </listbox>                 </datatemplate>             </tabcontrol.contenttemplate>         </tabcontrol>     </grid>  </stackpanel> 

[1]: peace of xaml work expected, uses wrappanel display groups contents:

<stackpanel x:key="modulselectinputparameterview">     <stackpanel.resources>         <collectionviewsource x:key="cvs" x:name="collectionviewsource" source="{binding referencedlmtitem.modulinputparametercollection }">             <collectionviewsource.groupdescriptions>                 <propertygroupdescription propertyname="category"/>             </collectionviewsource.groupdescriptions>         </collectionviewsource>     </stackpanel.resources>      <listbox itemssource="{binding source={staticresource cvs}}" verticalcontentalignment="top" itemcontainerstyle="{staticresource modulselectinputparameterlistboxitemcontainerstyle}" scrollviewer.horizontalscrollbarvisibility="disabled">         <listbox.groupstyle>             <groupstyle>                 <groupstyle.headertemplate>                     <datatemplate>                         <border borderbrush="darkgray" borderthickness="2" margin="2">                             <textblock fontweight="bold" fontsize="14" text="{binding path=name}" horizontalalignment="center" minwidth="100"/>                         </border>                     </datatemplate>                 </groupstyle.headertemplate>                 <groupstyle.panel>                     <itemspaneltemplate>                         <wrappanel orientation="horizontal" margin="2"/>                     </itemspaneltemplate>                 </groupstyle.panel>                 <groupstyle.containerstyle>                     <style targettype="{x:type groupitem}" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">                         <setter property="control.template">                             <setter.value>                                 <controltemplate targettype="{x:type groupitem}">                                     <border borderthickness="2" borderbrush="darkgray">                                         <stackpanel>                                             <contentpresenter content="{templatebinding contentcontrol.content}" contenttemplate="{templatebinding contentcontrol.contenttemplate}" contentstringformat="{templatebinding contentcontrol.contentstringformat}" />                                             <itemspresenter margin="2,0,2,2" />                                         </stackpanel>                                     </border>                                 </controltemplate>                             </setter.value>                         </setter>                     </style>                 </groupstyle.containerstyle>             </groupstyle>          </listbox.groupstyle>         <listbox.itemspanel>             <itemspaneltemplate>                 <wrappanel isitemshost="true" orientation="vertical" verticalalignment="top"/>             </itemspaneltemplate>         </listbox.itemspanel>      </listbox> </stackpanel> 

i think there's wrong binding code should work. same items in both listboxes try bind second listbox itemssource first listbox itemssource :

<listbox itemssource="{binding items}" name="listbox">                                      <listbox.itemtemplate>                                         <datatemplate>                                             <expander header="{binding key}">                                                 <listbox itemssource="{binding itemssource, elementname=listbox}">                                                      <listbox.itemtemplate>                                                         <datatemplate>                                                             <stackpanel orientation="horizontal">                                                                 <textblock text="{binding key}"/>                                                                 <textblock text=" - "/>                                                                 <textblock text="{binding value}"/>                                                             </stackpanel>                                                         </datatemplate>                                                     </listbox.itemtemplate>                                                 </listbox>                                             </expander>                                         </datatemplate>                                     </listbox.itemtemplate>                                 </listbox> 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -