NumericUpDown.xaml.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace PDF_Office.CustomControl
  16. {
  17. /// <summary>
  18. /// NumericUpDown.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class NumericUpDown : UserControl
  21. {
  22. public int Num
  23. {
  24. get
  25. {
  26. int value = 0;
  27. this.Dispatcher.Invoke(new Action(() =>
  28. value = Convert.ToInt32(this.TextBox_Num.Text.Trim())
  29. ));
  30. return value;
  31. }
  32. set
  33. {
  34. this.Dispatcher.Invoke(new Action(() =>
  35. {
  36. this.TextBox_Num.Text = value.ToString();
  37. }));
  38. }
  39. }
  40. public NumericUpDown()
  41. {
  42. InitializeComponent();
  43. }
  44. private void Button_Add_Click(object sender, RoutedEventArgs e)
  45. {
  46. int num = int.Parse(this.TextBox_Num.Text.Trim());
  47. if (num > 0)
  48. {
  49. this.TextBox_Num.Text = (num + 1).ToString();
  50. }
  51. }
  52. private void Button_Sub_Click(object sender, RoutedEventArgs e)
  53. {
  54. int num = int.Parse(this.TextBox_Num.Text.Trim());
  55. if (num > 0)
  56. {
  57. if ((num - 1) == 0)
  58. return;
  59. this.TextBox_Num.Text = (num - 1).ToString();
  60. }
  61. }
  62. public int MyProperty
  63. {
  64. get { return (int)GetValue(MyPropertyProperty); }
  65. set { SetValue(MyPropertyProperty, value); }
  66. }
  67. // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
  68. public static readonly DependencyProperty MyPropertyProperty =
  69. DependencyProperty.Register("MyProperty", typeof(int), typeof(NumericUpDown), new PropertyMetadata(0));
  70. }
  71. }