using System; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; using System.Windows.Media; using Aitex.Core.Common.DeviceData; namespace EfemUI.Controls { /// /// AITServoMotor.xaml 的交互逻辑 /// public partial class AITServoMotor : UserControl { public static readonly DependencyProperty AxisCommandProperty = DependencyProperty.Register( "AxisCommand", typeof(ICommand), typeof(AITServoMotor), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); public ICommand AxisCommand { get { return (ICommand)this.GetValue(AxisCommandProperty); } set { this.SetValue(AxisCommandProperty, value); } } public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register( "DeviceData", typeof(AITServoMotorData), typeof(AITServoMotor), new FrameworkPropertyMetadata(new AITServoMotorData(), FrameworkPropertyMetadataOptions.AffectsRender)); public AITServoMotorData DeviceData { get { return (AITServoMotorData)this.GetValue(DeviceDataProperty); } set { this.SetValue(DeviceDataProperty, value); } } public AITServoMotor() { InitializeComponent(); } protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); } private void OnPreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !IsTextAllowed(e.Text); } private static bool IsTextAllowed(string text) { Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text return !regex.IsMatch(text); } } public class CommandConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is string) { if (parameter != null) { return $"{parameter},{value}"; } } return value; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; } } }