Proper way to use CollectionViewSource in ViewModel

You have two options to use CollectionViewSource properly with MVVM – Expose an ObservableCollection of items (Categories in your case) through your ViewModel and create CollectionViewSource in XAML like this – <CollectionViewSource Source=”{Binding Path=Categories}”> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName=”CategoryName” /> </CollectionViewSource.SortDescriptions> </CollectionViewSource> scm: xmlns:scm=”clr-namespace:System.ComponentModel;assembly=Wind‌​owsBase” see this – Filtering collections from XAML using CollectionViewSource Create and Expose an … Read more

Grouping items in a ComboBox

It is possible. Use a ListCollectionView with a GroupDescription as the ItemsSource and just provide a GroupStyle to your 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> … Read more