private void tbxName_PreviewKeyUp(object sender, KeyEventArgs e) { ICountCollection countSource = (ICountCollection)ItemsSource; IRemoveAtCollection removeSource = (IRemoveAtCollection)ItemsSource; if (e.Key == SeparatorKey && !String.IsNullOrEmpty(tbxName.Text)) { RaiseEvent(new CreateItemEventArgs(CreateItemEvent, this, tbxName.Text)); //ViewModel.Items.Add(new CompletionItem { Name = textBox.Text }); tbxName.Text = String.Empty; } else if (e.Key == Key.Back && String.IsNullOrEmpty(tbxName.Text) && countSource.Count > 0) { removeSource.RemoveAt(countSource.Count - 1); } else if (e.Key == Key.Left && tbxName.CaretIndex == 0) { lvwItems.Focus(); lvwItems.SelectedIndex = countSource.Count - 1; UIListViewItem listViewItem = (UIListViewItem)lvwItems.ItemContainerGenerator.ContainerFromIndex(lvwItems.SelectedIndex); listViewItem.Focus(); e.Handled = true; } }
private void lvwItems_PreviewKeyUp(object sender, KeyEventArgs e) { ICountCollection countSource = (ICountCollection)ItemsSource; IRemoveAtCollection removeSource = (IRemoveAtCollection)ItemsSource; if ((e.Key == Key.Back || e.Key == Key.Delete) && lvwItems.SelectedItem != null) { removeSource.RemoveAt(lvwItems.SelectedIndex); tbxName.Focus(); } else if (e.Key == Key.Right && lvwItems.SelectedIndex == (countSource.Count - 1)) { tbxName.Focus(); } }