Here is an improvement on ASanch answer to make it MVVM friendly, where you bind to the CollectionView.
View Model:
namespace StackOverflow
{
public class MainViewModel : INotifyPropertyChanged
{
public ObservableCollection<Item> Items { get; set; }
public CollectionViewSource CollectionView { get; set; }
public MainViewModel()
{
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" });
Items = new ObservableCollection<Item>(items);
var view = new CollectionViewSource();
view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
view.Source = Items;
CollectionView = view;
}
public CollectionViewSource CollectionView { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
public class Item
{
public string Name { get; set; }
public string Category { get; set; }
}
}
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">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<StackPanel>
<ComboBox ItemsSource="{Binding CollectionView.View}" DisplayMemberPath="Name">
<ComboBox.GroupStyle>
<GroupStyle/>
</ComboBox.GroupStyle>
</ComboBox>
</StackPanel>
</Window>