wpf - Grouping items in a combobox -


i have listview contains 2 types of objects, single , multiple. single ordinary textblock while multiple combobox items.

i'm trying group items in combobox without success. possible? or should go different approach?

what i'm trying achieve:

[combobox v]     [header  ]     [    item]     [    item]     [header  ]     [    item] 

it possible. use listcollectionview groupdescription itemssource , provide groupstyle combobox. see sample below:

xaml:

<window x:class="stackoverflow.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:local="clr-namespace:stackoverflow"         xmlns:uc="clr-namespace:stackoverflow.usercontrols"         title="mainwindow" height="350" width="525">     <stackpanel>         <combobox x:name="combobox">             <combobox.groupstyle>                 <groupstyle>                     <groupstyle.headertemplate>                         <datatemplate>                             <textblock text="{binding name}"/>                         </datatemplate>                     </groupstyle.headertemplate>                 </groupstyle>             </combobox.groupstyle>             <combobox.itemtemplate>                 <datatemplate>                     <textblock text="{binding name}"/>                 </datatemplate>             </combobox.itemtemplate>         </combobox>     </stackpanel> </window> 

code-behind:

namespace stackoverflow {     /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     public partial class mainwindow : window     {          public mainwindow()         {             initializecomponent();             //this.combobox.datacontext = this;              list<item> items = new list<item>();             items.add(new item() { name = "item1", category = "a" });             items.add(new item() { name = "item2", category = "a" });             items.add(new item() { name = "item3", category = "a" });             items.add(new item() { name = "item4", category = "b" });             items.add(new item() { name = "item5", category = "b" });              listcollectionview lcv = new listcollectionview(items);             lcv.groupdescriptions.add(new propertygroupdescription("category"));              this.combobox.itemssource = lcv;         }       }      public class item     {         public string name { get; set; }         public string category { get; set; }     }  } 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -