using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace PDF_Office.CustomControl
{
///
/// NumericUpDown.xaml 的交互逻辑
///
public partial class NumericUpDown : UserControl
{
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(NumericUpDown), new PropertyMetadata("1"));
///
/// 当前值
///
public double Value
{
get { return (double)GetValue(ValueProperty); }
set
{
if (value > Maximum)
{
SetValue(ValueProperty, Maximum);
}
else if (value < Minimum)
{
SetValue(ValueProperty, Minimum);
}
else
{
SetValue(ValueProperty, value);
TextBox_Num.Text = Value.ToString();
}
}
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown), new PropertyMetadata(0.0));
///
/// 最大值
///
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));
///
/// 最小值
///
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));
///
/// 增长步长
///
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();
}
private void Button_Add_Click(object sender, RoutedEventArgs e)
{
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)
{
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 = 0;
double targetvalue = 0;
bool result = int.TryParse(this.TextBox_Num.Text.Trim(), out num);
if (result)
{
targetvalue = num - TickFrequency;
}
else
{
targetvalue = Minimum;
}
if(targetvalue