private void SendTrick(Trick trick) { if (TrickSelected != null) { TrickSelected(trick); selectedView = null; } }
private void tbInsert_PreviewKeyDown(object sender, KeyEventArgs e) { if (sideSelection) { Trick newTrick = selectedView.GetTrick(); if (e.Key == Key.Left) { newTrick.Side = Side.Left; } else if (e.Key == Key.Right) { newTrick.Side = Side.Right; } else { e.Handled = true; return; } SendTrick(newTrick); HideSideSelection(); } if (e.Key == Key.Enter && (searching || tbInsert.Text.Length == 0)) { stackPanelTricks.Children.Clear(); if (selectedView != null) { ShowSideSelection(); } else { if (tbInsert.Text.Length > 0) { return; } SendTrick(new Trick(0) { Name = "Drop", Side = Side.Drop }); } tbInsert.Text = ""; searching = false; selectedIndex = 0; } else if ((e.Key == Key.Left || e.Key == Key.Right) && searching) { e.Handled = true; } else if (e.Key == Key.Back) { searching = false; selectedIndex = 0; return; } else if (e.Key == Key.Down) { searching = true; if (stackPanelTricks.Children.Count == 0) { return; } if (selectedView != null) { selectedView.Dehighglight(); } selectedIndex++; if (selectedIndex > stackPanelTricks.Children.Count) { selectedIndex = 0; tbInsert.Text = searchText; tbInsert.CaretIndex = tbInsert.Text.Length; scrollViewerTricks.ScrollToVerticalOffset(0); searching = false; return; } selectedView = ((TrickView)stackPanelTricks.Children[selectedIndex - 1]); selectedView.Highlight(); if (selectedIndex > 5) { scrollViewerTricks.ScrollToVerticalOffset(scrollViewerTricks.VerticalOffset + 40); } tbInsert.Text = selectedView.Text; tbInsert.CaretIndex = tbInsert.Text.Length; } else if (e.Key == Key.Up) { if (stackPanelTricks.Children.Count == 0) { return; } if (selectedView != null) { selectedView.Dehighglight(); } selectedIndex--; if (selectedIndex <= 0) { selectedIndex = 0; tbInsert.Text = searchText; tbInsert.CaretIndex = tbInsert.Text.Length; searching = false; return; } if (selectedIndex <= Math.Max(1, stackPanelTricks.Children.Count - 5)) { scrollViewerTricks.ScrollToVerticalOffset(scrollViewerTricks.VerticalOffset - 40); } selectedView = ((TrickView)stackPanelTricks.Children[selectedIndex - 1]); selectedView.Highlight(); } }