|
@@ -90,7 +90,9 @@ namespace PDF_Master.CustomControl
|
|
|
public double Minimum
|
|
|
{
|
|
|
get { return (double)GetValue(MinimumProperty); }
|
|
|
- set { SetValue(MinimumProperty, value); }
|
|
|
+ set {
|
|
|
+ SetValue(MinimumProperty, value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static readonly DependencyProperty MinimumProperty =
|
|
@@ -123,7 +125,6 @@ namespace PDF_Master.CustomControl
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
public NumericUpDown()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -174,14 +175,29 @@ namespace PDF_Master.CustomControl
|
|
|
Value = targetvalue;
|
|
|
}
|
|
|
|
|
|
- private void TextBox_Num_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
+ {
|
|
|
+ e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void TextBox_Num_LostFocus(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ //校验输入的过程 放在失去焦点中,而不是放在放在文本变化事件中
|
|
|
+ //如果放在文本变化事件中 会影响用户正常的输入,体验比较别扭
|
|
|
+ CheckInput();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 校验输入是否合法
|
|
|
+ /// </summary>
|
|
|
+ private void CheckInput()
|
|
|
{
|
|
|
//控件未显示前不进行逻辑处理 避免初始化前卡顿
|
|
|
if (!this.IsLoaded)
|
|
|
return;
|
|
|
//int.TryParse("30.0000610351563"),字符串有小数点,会转换失败
|
|
|
double num = 0;
|
|
|
- if (this.TextBox_Num.Text == "" || !double.TryParse(this.TextBox_Num.Text,out num))
|
|
|
+ if (/*this.TextBox_Num.Text == "" ||*/ !double.TryParse(this.TextBox_Num.Text, out num))
|
|
|
{
|
|
|
this.TextBox_Num.Text = Minimum.ToString();
|
|
|
}
|
|
@@ -193,9 +209,17 @@ namespace PDF_Master.CustomControl
|
|
|
Value = (int)double.Parse(this.TextBox_Num.Text);
|
|
|
}
|
|
|
|
|
|
- private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
+ private void TextBox_Num_PreviewKeyDown(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
- e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
|
|
|
+ if (e.Key == Key.Enter)
|
|
|
+ {
|
|
|
+ CheckInput();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Text = Minimum.ToString();
|
|
|
}
|
|
|
}
|
|
|
}
|