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