1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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
- {
- /// <summary>
- /// NumericUpDown.xaml 的交互逻辑
- /// </summary>
- 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));
- }
- }
|