예제 #1
0
        private void ChangeEditKind(EditKind editKind)
        {
            if (editKind == _editKind)
            {
                return;
            }

            _editKind = editKind;
            switch (editKind)
            {
            case EditKind.None:
                // Make sure that the editor has focus
                if (ParentVisualElement != null)
                {
                    ParentVisualElement.Focus();
                }
                _margin.IsEditReadOnly = true;
                break;

            case EditKind.Command:
            case EditKind.SearchForward:
            case EditKind.SearchBackward:
                WpfKeyboard.Focus(_margin.CommandLineTextBox);
                _margin.IsEditReadOnly = false;
                break;

            default:
                Contract.FailEnumValue(editKind);
                break;
            }
        }
예제 #2
0
 private void LastOptionBtn_Click(object sender, RoutedEventArgs e)
 {
     if (FocusTb == null)
     {
         FocusTb = tbList[0];
     }
     else if (tbList.IndexOf(FocusTb) - 1 >= 0)
     {
         FocusTb = tbList[tbList.IndexOf(FocusTb) - 1];
     }
     Keyboard.Focus(FocusTb);
 }
예제 #3
0
 private void NextOptionBtn_Click(object sender, RoutedEventArgs e)
 {
     if (FocusTb == null)
     {
         FocusTb = tbList[0];
     }
     else if (tbList.IndexOf(FocusTb) + 1 < tbList.Count)
     {
         FocusTb = tbList[tbList.IndexOf(FocusTb) + 1];
     }
     Keyboard.Focus(FocusTb);
 }
예제 #4
0
        // verify this works with focus changes to FCEs
        // When FocusedElement property changes we need to update IsFocusedElement property on the old
        // and new FocusedElement elements
        private static void OnFocusedElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            IInputElement    newFocusedElement = (IInputElement)e.NewValue;
            DependencyObject oldVisual         = (DependencyObject)e.OldValue;
            DependencyObject newVisual         = (DependencyObject)e.NewValue;

            if (oldVisual != null)
            {
                oldVisual.ClearValue(UIElement.IsFocusedPropertyKey);
            }

            if (newVisual != null)
            {
                // set IsFocused on the element.  The element may redirect Keyboard focus
                // in response to this (e.g. Editable ComboBox redirects to the
                // child TextBox), so detect whether this happens.
                DependencyObject oldFocus = Keyboard.FocusedElement as DependencyObject;
                newVisual.SetValue(UIElement.IsFocusedPropertyKey, BooleanBoxes.TrueBox);
                DependencyObject newFocus = Keyboard.FocusedElement as DependencyObject;

                // set the Keyboard focus to the new element, provided that
                //  a) the element didn't already set Keyboard focus
                //  b) Keyboard focus is not already on the new element
                //  c) the new element is within the same focus scope as the current
                //      holder (if any) of Keyboard focus
                if (oldFocus == newFocus && newVisual != newFocus &&
                    (newFocus == null || GetRoot(newVisual) == GetRoot(newFocus)))
                {
                    Keyboard.Focus(newFocusedElement);
                }
            }

/*
 *          if (!_currentlyUpdatingTree)
 *          {
 *              _currentlyUpdatingTree = true;
 *
 *              IInputElement newFocusedElement = (IInputElement) newValue;
 *              Visual oldVisual = GetNearestVisual(args.OldValue);
 *              Visual newVisual = GetNearestVisual(args.NewValue);
 *
 *              if (oldVisual != null)
 *              {
 *                  oldVisual.ClearValue(UIElement.IsFocusedPropertyKey);
 *
 *                  // reverse-inherit:  clear the property on all parents that aren't also in the
 *                  // new focused element ancestry
 *                  while (oldVisual != null)
 *                  {
 *                      oldVisual.ClearValue(FocusedElementProperty);
 *                      oldVisual = VisualTreeHelper.GetParent(oldVisual);
 *                      if ((oldVisual == newVisual) || oldVisual.IsAncestorOf(newVisual))
 *                      {
 *                          // only walk up until you reach a common parent -- the new value walk will take care of the rest
 *                          break;
 *                      }
 *                  }
 *              }
 *
 *              if (newVisual != null)
 *              {
 *                  newVisual.SetValue(UIElement.IsFocusedPropertyKey, BooleanBoxes.TrueBox);
 *
 *                  // reverse-inherit:  set the property on all parents
 *                  while (newVisual != null)
 *                  {
 *                      newVisual.SetValue(FocusedElementProperty, newFocusedElement);
 *                      newVisual = VisualTreeHelper.GetParent(newVisual);
 *                  }
 *
 *                  // Set Keyboard focus to the element if not already focused && current focus is within the current focus scope
 *                  DependencyObject currentFocus = Keyboard.FocusedElement as DependencyObject;
 *                  if ((currentFocus == null) &&
 *                      (newVisual != currentFocus) &&
 *                      (GetRoot(newVisual) == GetRoot(currentFocus)))
 *                  {
 *                      Keyboard.Focus(newFocusedElement);
 *                  }
 *              }
 *              _currentlyUpdatingTree = false;
 *          }
 */
        }