using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; 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; using Aitex.Core.UI.MVVM; using Aitex.Triton160.UI.ViewModel; namespace Aitex.Triton160.UI.Views { /// /// HardwareConfigView.xaml 的交互逻辑 /// public partial class HardwareConfigView : UserControl { public HardwareConfigView() { InitializeComponent(); this.DataContext = new HardwareConfigViewModel(); this.IsVisibleChanged += HardwareConfigView_IsVisibleChanged; } void HardwareConfigView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if (IsVisible) (this.DataContext as HardwareConfigViewModel).UpdateConfig(); (this.DataContext as TimerViewModelBase).EnableTimer(this.IsVisible); } 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); } } }