Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible. Use a ListCollectionView with a GroupDescription as the ItemsSource and just provide a GroupStyle to your ComboBox. See sample below:</p> <p>XAML:</p> <pre><code>&lt;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"&gt; &lt;StackPanel&gt; &lt;ComboBox x:Name="comboBox"&gt; &lt;ComboBox.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.HeaderTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Name}"/&gt; &lt;/DataTemplate&gt; &lt;/GroupStyle.HeaderTemplate&gt; &lt;/GroupStyle&gt; &lt;/ComboBox.GroupStyle&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding Name}"/&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.ItemTemplate&gt; &lt;/ComboBox&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>Code-behind:</p> <pre><code>namespace StackOverflow { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); //this.comboBox.DataContext = this; List&lt;Item&gt; items = new List&lt;Item&gt;(); 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; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload