private void UpdateSource() { bool firstTime = (this.contactsView == null); if (this.dataSource != null) { this.dataSource.onItemPropChanged -= this.dataSource_onItemPropChanged; } this.dataSource = this.contactService.Contacts; this.dataSource.onItemPropChanged += this.dataSource_onItemPropChanged; this.listBox.ItemsSource = this.dataSource; this.contactsView = CollectionViewSource.GetDefaultView(this.listBox.ItemsSource); (this.contactsView as ListCollectionView).CustomSort = new ContactsSorter(); this.contactsView.GroupDescriptions.Clear(); this.contactsView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName")); IList <FilterItem> filterItems = new List <FilterItem>(); filterItems.Add(new FilterItem(null, "All Contacts", FilterItem.ImageSourceFromAuthorization(BogheXdm.Authorization.All))); foreach (Group g in this.contactService.Groups) { if (BogheXdm.SpecialNames.IsSpecial(g.Name)) { switch (g.Name) { case BogheXdm.SpecialNames.SHARED_RCS: case BogheXdm.SpecialNames.SHARED_RCS_BLOCKEDCONTACTS: case BogheXdm.SpecialNames.SHARED_RCS_REVOKEDCONTACTS: break; default: continue; } } filterItems.Add(new FilterItem(g.Name, g.DisplayName, FilterItem.ImageSourceFromAuthorization(g.Authorization))); } this.comboBoxGroups.ItemsSource = filterItems; this.comboBoxGroups.SelectedIndex = 0; this.contactsView.Filter = delegate(object c) { if (this.comboBoxGroups.SelectedIndex < 0) { return(true); } Contact contact = c as Contact; FilterItem fItem = this.comboBoxGroups.SelectedItem as FilterItem; if (fItem == null || contact == null || String.IsNullOrEmpty(contact.GroupName)) { return(false); } return((contact.DisplayName == null || contact.DisplayName.StartsWith(this.textBoxSearchCriteria.Text, StringComparison.InvariantCultureIgnoreCase)) && (fItem.Name == null || contact.GroupName.Equals(fItem.Name))); }; }