Browse Source

综合-调整窗体高度不够情况下,取色板的显示;调整偏少设置数字输入控件输入逻辑

ZhouJieSheng 1 year ago
parent
commit
a633fc1d8c

+ 6 - 0
PDF Office/CustomControl/ColorDropBox.xaml.cs

@@ -133,6 +133,12 @@ namespace PDF_Master.CustomControl
                 {
                     colorPop.SetValue(Canvas.LeftProperty, parentWnd.ActualWidth - colorPop.DesiredSize.Width - 5 - SystemParameters.ResizeFrameVerticalBorderWidth * 2);
                 }
+                else if(offset.Y+ colorPop.DesiredSize.Height+SystemParameters.ResizeFrameVerticalBorderWidth * 2 > parentWnd.ActualHeight)
+                {
+                    //超出窗体高度时 重新计算定位
+                    colorPop.SetValue(Canvas.TopProperty, parentWnd.ActualHeight - colorPop.DesiredSize.Height-15);
+                    colorPop.SetValue(Canvas.LeftProperty, offset.X+25);
+                }
                 else
                 {
                     colorPop.SetValue(Canvas.LeftProperty, offset.X);

+ 4 - 2
PDF Office/CustomControl/NumericUpDown.xaml

@@ -8,6 +8,7 @@
     d:DesignHeight="32"
     d:DesignWidth="80"
     FontSize="20"
+    Loaded="UserControl_Loaded"
     mc:Ignorable="d">
     <Border>
         <Grid>
@@ -28,14 +29,15 @@
                 VerticalContentAlignment="Center"
                 Background="Transparent"
                 BorderThickness="0"
+                LostFocus="TextBox_Num_LostFocus"
+                PreviewKeyDown="TextBox_Num_PreviewKeyDown"
                 FontFamily="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=FontFamily}"
                 FontSize="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=FontSize}"
                 Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=Foreground}"
                 InputMethod.IsInputMethodEnabled="False"
                 PreviewTextInput="CountTextBox_PreviewTextInput"
                 Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:NumericUpDown}, Path=Text}"
-                TextAlignment="Left"
-                TextChanged="TextBox_Num_TextChanged" />
+                TextAlignment="Left" />
             <Grid Grid.Column="1" Width="16">
                 <Grid.RowDefinitions>
                     <RowDefinition />

+ 30 - 6
PDF Office/CustomControl/NumericUpDown.xaml.cs

@@ -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();
         }
     }
 }