protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            if (!isFilterActive &&
                ((e.Key > Key.A && e.Key < Key.Z) ||
                 (e.Key > Key.OemSemicolon && e.Key < Key.Oem102)))
            {
                // Start activating the filter on the first key stroke.
                isFilterActive = true;
            }
            else if (isFilterActive && e.Key == Key.Return)
            {
                // When the filter is active and the user press return we handle it
                // by closing the drop-down and select the whole text.
                // If the auto-complete feature of the combo box had select an item this
                // item will be left selected, otherwise the text the user enter will
                // remain in the editable text box.
                // If we do not handle this case the combo box will clear the combo box because
                // during filtering no item is selected in the drop-down so the combo box does
                // not use auto-complete's selected item.
                object selectedValue = SelectedValue;
                ClearFilter();
                e.Handled      = true;
                IsDropDownOpen = false;
                EditableTextBox.SelectAll();
                SelectedValue = selectedValue;
                return;
            }

            base.OnPreviewKeyDown(e);
        }
Ejemplo n.º 2
0
 private void EditableTextBox_GotKeyboardFocus(object sender, RoutedEventArgs e)
 {
     if (ignoreFocus)
     {
         ignoreFocus = false;
     }
     else
     {
         EditableTextBox.SelectAll();
     }
 }
        protected override void OnPreviewKeyDown(KeyEventArgs e)
        {
            if (!_isFilterActive &&
                ((e.Key >= Key.A && e.Key <= Key.Z) ||
                 (e.Key > Key.OemSemicolon && e.Key < Key.Oem102)))
            {
                _isFilterActive = true;
            }
            else if (_isFilterActive && e.Key == Key.Return)
            {
                var selectedValue = SelectedValue;
                ClearFilter();
                e.Handled      = true;
                IsDropDownOpen = false;
                EditableTextBox.SelectAll();
                SelectedValue = selectedValue;
                return;
            }

            base.OnPreviewKeyDown(e);
        }
 private void RestoreSavedText()
 {
     Text = _textSaved ? _savedText : "";
     EditableTextBox.SelectAll();
 }