示例#1
0
        private static void NumTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var tb = d as TextBox;

            if (tb == null)
            {
                return;
            }

            tb.PreviewTextInput -= tbb_PreviewTextInput;
            tb.PreviewKeyDown   -= tbb_PreviewKeyDown;
            DataObject.RemovePastingHandler(tb, OnClipboardPaste);
            NumTextType result = (NumTextType)e.NewValue;

            if (result != NumTextType.Default)
            {
                InputMethod.SetIsInputMethodEnabled(tb, false);
                tb.PreviewTextInput += tbb_PreviewTextInput;
                tb.PreviewKeyDown   += tbb_PreviewKeyDown;
                DataObject.AddPastingHandler(tb, OnClipboardPaste);
            }
            else
            {
                InputMethod.SetIsInputMethodEnabled(tb, true);
            }
        }
示例#2
0
        //isDigit是否是数字
        public static bool isNumberic(string _string, string allstr, NumTextType type)
        {
            if (string.IsNullOrEmpty(_string))
            {
                return(false);
            }
            foreach (char c in _string)
            {
                switch (type)
                {
                case NumTextType.Int:
                    if (!char.IsDigit(c))
                    {
                        return(false);
                    }
                    break;

                case NumTextType.Float:
                    if (!char.IsDigit(c) && c != '.')
                    {
                        return(false);
                    }
                    break;

                case NumTextType.Negative:
                    if (!char.IsDigit(c) && c != '.' && c != '-')
                    {
                        return(false);
                    }
                    break;
                }
            }
            if (type == NumTextType.Float || type == NumTextType.Negative)
            {
                if (!double.TryParse(allstr, out double result))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
 public static void SetNumText(DependencyObject obj, NumTextType value)
 {
     obj.SetValue(NumTextProperty, value);
 }