Beispiel #1
0
        /// <summary>
        /// Handles the KeyDown event of the textBox control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs"/> instance containing the event data.</param>
        private static void textBox_KeyDown(object sender, KeyEventArgs e)
        {
            // bypass other keys!
            if (IsValidOtherKey(e.Key))
            {
                return;
            }
            //
            TextBoxFilterType filterType = GetFilter((DependencyObject)sender);
            TextBox           textBox    = sender as TextBox;

            if (null == textBox)
            {
                textBox = e.OriginalSource as TextBox;
            }
            //
            switch (filterType)
            {
            case TextBoxFilterType.PositiveInteger:
                e.Handled = !IsValidIntegerKey(textBox, e.Key, e.PlatformKeyCode, false);
                break;

            case TextBoxFilterType.Integer:
                e.Handled = !IsValidIntegerKey(textBox, e.Key, e.PlatformKeyCode, true);
                break;

            case TextBoxFilterType.PositiveDecimal:
                e.Handled = !IsValidDecmialKey(textBox, e.Key, e.PlatformKeyCode, false);
                break;

            case TextBoxFilterType.Decimal:
                e.Handled = !IsValidDecmialKey(textBox, e.Key, e.PlatformKeyCode, true);
                break;

            case TextBoxFilterType.Alpha:
                e.Handled = !IsValidAlphaKey(e.Key);
                break;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Sets the Filter property.
 /// </summary>
 public static void SetFilter(DependencyObject d, TextBoxFilterType value)
 {
     d.SetValue(FilterProperty, value);
 }
Beispiel #3
0
 /// <summary>
 /// Sets the Filter property.  
 /// </summary>
 public static void SetFilter(DependencyObject d, TextBoxFilterType value)
 {
     d.SetValue(FilterProperty, value);
 }