Пример #1
0
        /// <summary>
        /// Validates the current changes in the TextBox.
        /// </summary>
        public void Validate()
        {
            var cancelRoutedEventArgs = new CancelRoutedEventArgs(ValidatingEvent);
            OnValidating(cancelRoutedEventArgs);
            if (cancelRoutedEventArgs.Cancel)
                return;

            RaiseEvent(cancelRoutedEventArgs);
            if (cancelRoutedEventArgs.Cancel)
                return;

            validating = true;
            var coercedText = CoerceTextForValidation(Text);
            SetCurrentValue(TextProperty, coercedText);

            BindingExpression expression = GetBindingExpression(TextProperty);
            if (expression != null)
                expression.UpdateSource();

            ClearUndoStack();

            var validatedArgs = new ValidationRoutedEventArgs<string>(ValidatedEvent, coercedText);
            OnValidated();

            RaiseEvent(validatedArgs);
            if (ValidateCommand != null && ValidateCommand.CanExecute(ValidateCommandParameter))
                ValidateCommand.Execute(ValidateCommandParameter);
            validating = false;
        }
Пример #2
0
        private void EditableTextBoxValidated(object sender, ValidationRoutedEventArgs<string> e)
        {
            // This may happens somehow when the template is refreshed.
            if (!ReferenceEquals(sender, editableTextBox))
                return;

            var validatedArgs = new RoutedEventArgs(ValidatedEvent);
            RaiseEvent(validatedArgs);

            if (ClearTextAfterValidation)
            {
                clearing = true;
                editableTextBox.Text = string.Empty;
                clearing = false;
            }
        }
Пример #3
0
 private void EditableTextBoxValidated(object sender, ValidationRoutedEventArgs<string> e)
 {
     if (!IsDropDownOpen && !clearing && IsKeyboardFocusWithin)
     {
         // Setting IsDropDownOpen to true will select all the text. We don't want this behavior, so let's save and restore the caret index.
         var index = editableTextBox.CaretIndex;
         IsDropDownOpen = true;
         editableTextBox.CaretIndex = index;
     }
 }