using System; using System.Collections.Generic; using System.Linq; using System.Text; 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 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 NumericUpDown() { InitializeComponent(); } private void Button_Add_Click(object sender, RoutedEventArgs e) { int num = int.Parse(this.TextBox_Num.Text.Trim()); if (num > 0) { this.TextBox_Num.Text = (num + 1).ToString(); } } private void Button_Sub_Click(object sender, RoutedEventArgs e) { int num = int.Parse(this.TextBox_Num.Text.Trim()); if (num > 0) { if ((num - 1) == 0) return; this.TextBox_Num.Text = (num - 1).ToString(); } } public int MyProperty { get { return (int)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } } // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(int), typeof(NumericUpDown), new PropertyMetadata(0)); } }