private void OnItemTapped(object sender, C1TappedEventArgs e) { e.Handled = true; SuggestListPopup.IsOpen = false; C1ListBoxItem item = sender as C1ListBoxItem; string tag = (item.Content as Mail)?.Name?.Trim(); if (!string.IsNullOrEmpty(tag) && !AddressEditor.Text.Contains(tag)) { // add new tag AddressEditor.InsertTag(tag); AddressEditor.SetEditorText(string.Empty); AddressEditor.Focus(FocusState.Programmatic); Mail selectedMail = Mails[MyIndexOf(tag)]; _changedSelectedItemsInternal = true; if (ContactList.SelectedItems == null) { object[] selectedItems = new object[] { selectedMail }; ContactList.SelectedItems = selectedItems; } else { object[] selectedItems = ContactList.SelectedItems as object[]; var list = selectedItems.ToList(); if (!list.Contains(selectedMail)) { list.Add(selectedMail); ContactList.SelectedItems = list.ToArray(); } } _changedSelectedItemsInternal = false; } }
private void OnListBoxSelectionChanged(object sender, SelectionChangedEventArgs <int> e) { if (_changedSelectedItemsInternal) { return; } foreach (int index in e.AddedItems) { Mail item = (Mail)ContactList.Items[index]; _changedSelectedItemsInternal = true; AddressEditor.InsertTag(item.Name); AddressEditor.SetEditorText(string.Empty); _changedSelectedItemsInternal = false; AddressEditor.Focus(FocusState.Programmatic); } foreach (int index in e.RemovedItems) { Mail item = (Mail)ContactList.Items[index]; _changedSelectedItemsInternal = true; RemoveTagByName(item.Name); _changedSelectedItemsInternal = false; } }