Numeric Data Entry in WPF

前端 未结 17 2609
情话喂你
情话喂你 2020-12-02 05:38

How are you handling the entry of numeric values in WPF applications?

Without a NumericUpDown control, I\'ve been using a TextBox and handling its PreviewKeyDown eve

17条回答
  •  余生分开走
    2020-12-02 06:11

    Can also use a converter like:

    public class IntegerFormatConverter : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int result;
            int.TryParse(value.ToString(), out result);
            return result;
        }
    
        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int result;
            int.TryParse(value.ToString(), out result);
            return result;
        }
    }
    

提交回复
热议问题