|
@@ -21,24 +21,116 @@ namespace PDF_Office.CustomControl
|
|
|
/// </summary>
|
|
|
public partial class NumericUpDown : UserControl
|
|
|
{
|
|
|
- public int Num
|
|
|
+ //public int Num
|
|
|
+ //{
|
|
|
+ // get
|
|
|
+ // {
|
|
|
+ // int value = 0;
|
|
|
+ // this.Dispatcher.Invoke(new Action(() =>
|
|
|
+ // value = Convert.ToInt32(this.TextBox_Num.Text.Trim())
|
|
|
+ // ));
|
|
|
+ // return value;
|
|
|
+ // }
|
|
|
+ // set
|
|
|
+ // {
|
|
|
+ // this.Dispatcher.Invoke(new Action(() =>
|
|
|
+ // {
|
|
|
+ // this.TextBox_Num.Text = value.ToString();
|
|
|
+ // }));
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ public string Text
|
|
|
{
|
|
|
- get
|
|
|
- {
|
|
|
- int value = 0;
|
|
|
- this.Dispatcher.Invoke(new Action(() =>
|
|
|
- value = Convert.ToInt32(this.TextBox_Num.Text.Trim())
|
|
|
- ));
|
|
|
- return value;
|
|
|
- }
|
|
|
- set
|
|
|
- {
|
|
|
- this.Dispatcher.Invoke(new Action(() =>
|
|
|
+ get { return (string)GetValue(TextProperty); }
|
|
|
+ set { SetValue(TextProperty, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly DependencyProperty TextProperty =
|
|
|
+ DependencyProperty.Register("Text", typeof(string), typeof(NumericUpDown), new PropertyMetadata(""));
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 当前值
|
|
|
+ /// </summary>
|
|
|
+ public double Value
|
|
|
+ {
|
|
|
+ get { return (double)GetValue(ValueProperty); }
|
|
|
+ set {
|
|
|
+ if (value > Maximum)
|
|
|
+ {
|
|
|
+ SetValue(ValueProperty, Maximum);
|
|
|
+ }
|
|
|
+ else if (value < Minimum)
|
|
|
+ {
|
|
|
+ SetValue(ValueProperty, Minimum);
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- this.TextBox_Num.Text = value.ToString();
|
|
|
- }));
|
|
|
+ SetValue(ValueProperty, value);
|
|
|
+ TextBox_Num.Text = Value.ToString();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static readonly DependencyProperty ValueProperty =
|
|
|
+ DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown), new PropertyMetadata(0.0));
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 最大值
|
|
|
+ /// </summary>
|
|
|
+ public double Maximum
|
|
|
+ {
|
|
|
+ get { return (double)GetValue(MaximumProperty); }
|
|
|
+ set { SetValue(MaximumProperty, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly DependencyProperty MaximumProperty =
|
|
|
+ DependencyProperty.Register("Maximum", typeof(double), typeof(NumericUpDown), new PropertyMetadata(9999.0));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 最小值
|
|
|
+ /// </summary>
|
|
|
+ public double Minimum
|
|
|
+ {
|
|
|
+ get { return (double)GetValue(MinimumProperty); }
|
|
|
+ set { SetValue(MinimumProperty, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly DependencyProperty MinimumProperty =
|
|
|
+ DependencyProperty.Register("Minimum", typeof(double), typeof(NumericUpDown), new PropertyMetadata(0.0));
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 增长步长
|
|
|
+ /// </summary>
|
|
|
+
|
|
|
+ public double TickFrequency
|
|
|
+ {
|
|
|
+ get { return (double)GetValue(TickFrequencyProperty); }
|
|
|
+ set { SetValue(TickFrequencyProperty, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly DependencyProperty TickFrequencyProperty =
|
|
|
+ DependencyProperty.Register("TickFrequency", typeof(double), typeof(NumericUpDown), new PropertyMetadata(1.0));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Visibility ShowBtn
|
|
|
+ {
|
|
|
+ get { return (Visibility)GetValue(ShowBtnProperty); }
|
|
|
+ set { SetValue(ShowBtnProperty, value); }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static readonly DependencyProperty ShowBtnProperty =
|
|
|
+ DependencyProperty.Register("ShowBtn", typeof(Visibility), typeof(NumericUpDown), new PropertyMetadata(Visibility.Visible));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public NumericUpDown()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -46,45 +138,58 @@ namespace PDF_Office.CustomControl
|
|
|
|
|
|
private void Button_Add_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- int num = int.Parse(this.TextBox_Num.Text.Trim());
|
|
|
- if (num > 0)
|
|
|
+ int num = 0;
|
|
|
+ double targetvalue = 0;
|
|
|
+ bool result = int.TryParse(this.TextBox_Num.Text.Trim(), out num);
|
|
|
+ if (result)
|
|
|
+ {
|
|
|
+ targetvalue = num + TickFrequency;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ targetvalue = Maximum;
|
|
|
+ }
|
|
|
+ if(targetvalue>Maximum)
|
|
|
{
|
|
|
- this.TextBox_Num.Text = (num + 1).ToString();
|
|
|
- Text = this.TextBox_Num.Text;
|
|
|
+ targetvalue = Maximum;
|
|
|
}
|
|
|
+ this.TextBox_Num.Text = targetvalue.ToString();
|
|
|
+ Text = this.TextBox_Num.Text;
|
|
|
+ Value = targetvalue;
|
|
|
}
|
|
|
|
|
|
private void Button_Sub_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- int num = int.Parse(this.TextBox_Num.Text.Trim());
|
|
|
- if (num > 0)
|
|
|
+ int num = 0;
|
|
|
+ double targetvalue = 0;
|
|
|
+ bool result = int.TryParse(this.TextBox_Num.Text.Trim(), out num);
|
|
|
+ if (result)
|
|
|
{
|
|
|
- if ((num - 1) == 0)
|
|
|
- return;
|
|
|
- this.TextBox_Num.Text = (num - 1).ToString();
|
|
|
- Text = this.TextBox_Num.Text;
|
|
|
+ targetvalue = num - TickFrequency;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ targetvalue = Minimum;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
- public string Text
|
|
|
- {
|
|
|
- get { return (string)GetValue(TextProperty); }
|
|
|
- set { SetValue(TextProperty, value); }
|
|
|
+ if(targetvalue<Minimum)
|
|
|
+ {
|
|
|
+ targetvalue = Minimum;
|
|
|
+ }
|
|
|
+ this.TextBox_Num.Text = targetvalue.ToString();
|
|
|
+ Text = this.TextBox_Num.Text;
|
|
|
+ Value = targetvalue;
|
|
|
}
|
|
|
|
|
|
- // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
|
|
|
- public static readonly DependencyProperty TextProperty =
|
|
|
- DependencyProperty.Register("Text", typeof(string), typeof(NumericUpDown), new PropertyMetadata(""));
|
|
|
-
|
|
|
private void TextBox_Num_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
{
|
|
|
- if (this.TextBox_Num.Text == "" || int.Parse(this.TextBox_Num.Text) < 1)
|
|
|
+ int num = 0;
|
|
|
+ if (this.TextBox_Num.Text == "" || !int.TryParse(this.TextBox_Num.Text,out num))
|
|
|
{
|
|
|
- this.TextBox_Num.Text = "1";
|
|
|
+ this.TextBox_Num.Text = Minimum.ToString();
|
|
|
}
|
|
|
Text = this.TextBox_Num.Text;
|
|
|
+ Value = int.Parse(this.TextBox_Num.Text);
|
|
|
}
|
|
|
|
|
|
private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
|