AITServoMotor.xaml.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Input;
  7. using System.Windows.Media;
  8. using Aitex.Core.Common.DeviceData;
  9. namespace EfemUI.Controls
  10. {
  11. /// <summary>
  12. /// AITServoMotor.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class AITServoMotor : UserControl
  15. {
  16. public static readonly DependencyProperty AxisCommandProperty = DependencyProperty.Register(
  17. "AxisCommand", typeof(ICommand), typeof(AITServoMotor),
  18. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  19. public ICommand AxisCommand
  20. {
  21. get
  22. {
  23. return (ICommand)this.GetValue(AxisCommandProperty);
  24. }
  25. set
  26. {
  27. this.SetValue(AxisCommandProperty, value);
  28. }
  29. }
  30. public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
  31. "DeviceData", typeof(AITServoMotorData), typeof(AITServoMotor),
  32. new FrameworkPropertyMetadata(new AITServoMotorData(), FrameworkPropertyMetadataOptions.AffectsRender));
  33. public AITServoMotorData DeviceData
  34. {
  35. get
  36. {
  37. return (AITServoMotorData)this.GetValue(DeviceDataProperty);
  38. }
  39. set
  40. {
  41. this.SetValue(DeviceDataProperty, value);
  42. }
  43. }
  44. public AITServoMotor()
  45. {
  46. InitializeComponent();
  47. }
  48. protected override void OnRender(DrawingContext drawingContext)
  49. {
  50. base.OnRender(drawingContext);
  51. }
  52. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  53. {
  54. e.Handled = !IsTextAllowed(e.Text);
  55. }
  56. private static bool IsTextAllowed(string text)
  57. {
  58. Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
  59. return !regex.IsMatch(text);
  60. }
  61. }
  62. public class CommandConverter : IValueConverter
  63. {
  64. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  65. {
  66. if (value is string)
  67. {
  68. if (parameter != null)
  69. {
  70. return $"{parameter},{value}";
  71. }
  72. }
  73. return value;
  74. }
  75. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  76. {
  77. return value;
  78. }
  79. }
  80. }