Ejemplo n.º 1
0
        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            TextBox textBox = (TextBox)e.OriginalSource;
            string  text    = textBox.SelectionLength > 0 ? textBox.Text.Remove(textBox.SelectionStart, textBox.SelectionLength) : textBox.Text;

            text      = text.Insert(textBox.CaretIndex, e.Text);
            e.Handled = !NumericProperties.IsStringNumeric(text, np);
            base.OnPreviewTextInput(e);
        }
Ejemplo n.º 2
0
        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            TextBox textBox = (TextBox)e.OriginalSource;
            string  text    = textBox.SelectionLength > 0 ? textBox.Text.Remove(textBox.SelectionStart, textBox.SelectionLength) : textBox.Text;

            text = text.Insert(textBox.CaretIndex, e.Text);
            if (!(e.Handled = !NumericProperties.IsStringNumeric(text, np)))
            {
                updateText = false;
                Value      = double.Parse(text == "" || text == "." || text == "-" || text == "-." ? "0" : text, np.Styles, CultureInfo.InvariantCulture);
                updateText = true;
            }

            base.OnPreviewTextInput(e);
        }