12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- 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
- {
- /// <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();
- Text = this.TextBox_Num.Text;
- }
- }
- 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();
- Text = this.TextBox_Num.Text;
- }
- }
-
-
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
- // 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)
- {
- Text = this.TextBox_Num.Text;
- }
- private void CountTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
- {
- e.Handled = new Regex("[^0-9]+").IsMatch(e.Text);
- }
- }
- }
|