123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using SciChart.Core.Extensions;
- 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 MECF.Framework.UI.Core.Control
- {
- /// <summary>
- /// PMCounterValueTextBox.xaml 的交互逻辑
- /// </summary>
- public partial class PMCounterValueTextBox : UserControl
- {
- public PMCounterValueTextBox()
- {
- InitializeComponent();
-
- }
- public static readonly DependencyProperty KeyOperationProperty = DependencyProperty.Register("KeyOperation", typeof(ICommand), typeof(PMCounterValueTextBox));
- public ICommand KeyOperation
- {
- get
- {
- return (ICommand)this.GetValue(KeyOperationProperty);
- }
- set
- {
- this.SetValue(KeyOperationProperty, value);
- }
- }
- public static readonly DependencyProperty PMCounterNodeNameProperty = DependencyProperty.Register(
- "PMCounterNodeName", typeof(string), typeof(PMCounterValueTextBox), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// PMCounter名称
- /// </summary>
- public string PMCounterNodeName
- {
- get
- {
- return (string)this.GetValue(PMCounterNodeNameProperty);
- }
- set
- {
- this.SetValue(PMCounterNodeNameProperty, value);
- }
- }
- public static readonly DependencyProperty CounterNodeNameProperty = DependencyProperty.Register(
- "CounterNodeName", typeof(string), typeof(PMCounterValueTextBox), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// PMcounter项目名称
- /// </summary>
- public string CounterNodeName
- {
- get
- {
- return (string)this.GetValue(CounterNodeNameProperty);
- }
- set
- {
- this.SetValue(CounterNodeNameProperty, value);
- }
- }
- public static readonly DependencyProperty CounterNodeItemIndexProperty = DependencyProperty.Register(
- "CounterNodeItemIndex", typeof(string), typeof(PMCounterValueTextBox), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// PMcounterItem Index
- /// </summary>
- public string CounterNodeItemIndex
- {
- get
- {
- return (string)this.GetValue(CounterNodeItemIndexProperty);
- }
- set
- {
- this.SetValue(CounterNodeItemIndexProperty, value);
- }
- }
- public static readonly DependencyProperty IsHeaderProperty = DependencyProperty.Register(
- "IsHeader", typeof(bool), typeof(PMCounterValueTextBox), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// IsHeader
- /// </summary>
- public bool IsHeader
- {
- get
- {
- return (bool)this.GetValue(IsHeaderProperty);
- }
- set
- {
- this.SetValue(IsHeaderProperty, value);
- }
- }
- public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
- "Value", typeof(string), typeof(PMCounterValueTextBox), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 数值
- /// </summary>
- public string Value
- {
- get
- {
- return (string)this.GetValue(ValueProperty);
- }
- set
- {
- this.SetValue(ValueProperty, value);
- }
- }
- private void TextBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Enter)
- {
- if (KeyOperation != null)
- {
- if (txtInput.Text.IsNullOrEmpty())
- {
- txtInput.Text = "0";
- }
- Value = txtInput.Text;
- KeyOperation.Execute(new object[] { PMCounterNodeName, CounterNodeName , txtInput.Text });
- }
- }
- }
- private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
- {
- e.Handled = !IsTextAllowed(e.Text, ((TextBox)sender).Text);
- }
- private bool IsTextAllowed(string key, string text)
- {
- Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
- return !regex.IsMatch(key);
- }
- private void TextBox_LostFocus(object sender, RoutedEventArgs e)
- {
- TextBox textBox = sender as TextBox;
- if (textBox != null && string.IsNullOrEmpty(textBox.Text))
- {
- textBox.Text = Value;
- }
- if (Value != textBox.Text)
- {
- textBox.Text = Value;
- }
- }
- }
- }
|