Explorar el Código

Form - 表单域、ToolTip绑定问题

chenrongqian hace 2 años
padre
commit
ff25f7128c

+ 15 - 5
PDF Office/CustomControl/NumericUpDown.xaml.cs

@@ -41,6 +41,7 @@ namespace PDF_Office.CustomControl
             get { return (double)GetValue(ValueProperty); }
             set
             {
+                SetValue(ValueProperty, value);
                 if (value > Maximum)
                 {
                     SetValue(ValueProperty, Maximum);
@@ -58,9 +59,17 @@ namespace PDF_Office.CustomControl
         }
 
         public static readonly DependencyProperty ValueProperty =
-            DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown), new PropertyMetadata(0.0));
-
+            DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown), new PropertyMetadata(0.0, SelectedItemSourcePropertyChanged));
 
+        private static void SelectedItemSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var control = d as NumericUpDown;
+            var value = (double)e.NewValue;
+            if (control != null)
+            {
+                control.TextBox_Num.Text = Convert.ToString(value);
+            }
+        }
         /// <summary>
         /// 最大值
         /// </summary>
@@ -167,13 +176,14 @@ namespace PDF_Office.CustomControl
 
         private void TextBox_Num_TextChanged(object sender, TextChangedEventArgs e)
         {
-            int num = 0;
-            if (this.TextBox_Num.Text == "" || !int.TryParse(this.TextBox_Num.Text,out num))
+            //int.TryParse("30.0000610351563"),字符串有小数点,会转换失败
+            double num = 0;
+            if (this.TextBox_Num.Text == "" || !double.TryParse(this.TextBox_Num.Text,out num))
             {
                 this.TextBox_Num.Text = Minimum.ToString();
             }
             Text = this.TextBox_Num.Text;
-            Value = int.Parse(this.TextBox_Num.Text);
+            Value = (int)double.Parse(this.TextBox_Num.Text);
         }
 
         private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)

+ 2 - 2
PDF Office/Views/Form/ButtonProperty.xaml

@@ -95,7 +95,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -106,7 +106,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>

+ 2 - 2
PDF Office/Views/Form/CheckBoxProperty.xaml

@@ -95,7 +95,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -106,7 +106,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>

+ 2 - 2
PDF Office/Views/Form/ComboxProperty.xaml

@@ -95,7 +95,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -106,7 +106,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>

+ 2 - 2
PDF Office/Views/Form/ListBoxProperty.xaml

@@ -95,7 +95,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -106,7 +106,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>

+ 2 - 2
PDF Office/Views/Form/RadioButtonProperty.xaml

@@ -95,7 +95,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -106,7 +106,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>

+ 2 - 2
PDF Office/Views/Form/SignProperty.xaml

@@ -95,7 +95,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -106,7 +106,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>

+ 2 - 2
PDF Office/Views/Form/TextFieldProperty.xaml

@@ -98,7 +98,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="ToolTip" />
-                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" >
+                    <cus:TextBoxEx x:Name="TbToolTip" Height="32" CornerRadius="4" Text="{Binding ToolTipStr,Mode=TwoWay}">
                         <i:Interaction.Triggers>
                             <i:EventTrigger EventName="TextChanged">
                                 <i:InvokeCommandAction Command="{Binding ToolTipTextChangedCommand}" CommandParameter="{Binding ElementName=TbToolTip,Path=Text}"/>
@@ -109,7 +109,7 @@
                         Margin="0,18,0,10"
                         Style="{StaticResource PropertyHeaderLv2}"
                         Text="Form Field" />
-                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=OneWay}" Height="32" Margin="0,8,0,16" />
+                    <form:FormFieldCombox x:Name="formCombox" Type="{Binding FormField,Mode=TwoWay}" Height="32" Margin="0,8,0,16" />
                     <CheckBox x:Name="ReadOnlyCheckBox" Content="Read Only" IsChecked="{Binding IsReadOnly,Mode=TwoWay}"/>
                     <CheckBox x:Name="RequiredFieldCheckBox" Margin="0,8" Content="Required field" IsChecked="{Binding IsRequiredField,Mode=TwoWay}" />
                 </StackPanel>