private void DownStyleChange(Label label)
 {
     if (label == null)
     {
         CollectionStack.SelectItem = CollectionSource.First();
     }
     else
     {
         int index = CollectionSource.ToList().IndexOf(label);
         if (index != CollectionSource.Count() - 1)
         {
             int offset = GetScrollViewerOffset();
             if (offset + 9 == index)
             {
                 SetScrollViewerOffset(offset + 1);
             }
             else if (offset > index || offset + 9 < index)
             {
                 SetScrollViewerOffset(index + 1);
             }
             StyleChange(label);
             CollectionStack.SelectItem = CollectionSource.ElementAt(index + 1);
         }
     }
 }
        private void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            Label label = CollectionStack.SelectItem;

            if (CollectionSource.Count() != 0)
            {
                if (e.KeyCode == System.Windows.Forms.Keys.Up)
                {
                    UpStyleChange(label);
                    SetPopup(CollectionStack.SelectItem);
                    e.Handled = true;
                }
                if (e.KeyCode == System.Windows.Forms.Keys.Down)
                {
                    DownStyleChange(label);
                    SetPopup(CollectionStack.SelectItem);
                    e.Handled = true;
                }
            }
        }
 private void OnWindowKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         this.Close();
     }
     if (e.Key == Key.Enter)
     {
         if (CollectionSource.Count() != 0)
         {
             Label label = CollectionStack.SelectItem;
             if (label != null)
             {
                 if (label.Content as string != oldText)
                 {
                     InstructionInputTextBox.Tag = "true";
                     string[] words = InstructionInputTextBox.Text.Split(' ');
                     words[words.Length - 1]      = label.Content as string;
                     InstructionInputTextBox.Text = words[0];
                     for (int i = 1; i < words.Length; i++)
                     {
                         InstructionInputTextBox.Text += " " + words[i];
                     }
                     InstructionInputTextBox.SelectionStart = InstructionInputTextBox.Text.Length;
                     //InstructionInputTextBox.Text = label.Content as string;
                 }
                 else
                 {
                     ResetStatus(label);
                 }
             }
         }
         else
         {
             EnsureButton.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
         }
     }
 }