123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System.Text.RegularExpressions;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using Aitex.Core.Account;
- using Aitex.Core.UI.MVVM;
- using Triton160.UI.ViewModel;
- namespace Aitex.Triton160.UI.Views.Hz
- {
- /// <summary>
- /// HzOverviewView.xaml 的交互逻辑
- /// </summary>
- public partial class HzOverviewView : UserControl
- {
- private OverviewViewModel _vm;
- public HzOverviewView()
- {
- InitializeComponent();
- _vm = new OverviewViewModel(this);
- this.DataContext = _vm;
- this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(OverviewView_IsVisibleChanged);
- this.Loaded += OverviewView_Loaded;
- }
- void OverviewView_Loaded(object sender, RoutedEventArgs e)
- {
- OverviewViewModel model = this.DataContext as OverviewViewModel;
- this.Name = "overview";
- var permission = this.GetPermission();
- switch (permission)
- {
- case ViewPermission.PartlyControl:
- //canvasGraphicDevice.IsEnabled = false;
- gridMonitorTable.IsEnabled = false;
- groupManualOperation.IsEnabled = false;
- break;
- default:
- break;
- }
- model.IsFullControlPermission = permission == ViewPermission.FullyControl;
- }
- void OverviewView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- (this.DataContext as TimerViewModelBase).EnableTimer(this.IsVisible);
- }
- private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
- {
- e.Handled = !IsTextAllowed(e.Text);
- }
- private void InputTextBoxPower_TextChanged(object sender, TextChangedEventArgs e)
- {
- double input;
- bool enable = true;
- if (!double.TryParse((sender as TextBox).Text, out input))
- enable = false;
- else if (input < 0 || input > _vm.Rf.ScalePower)
- enable = false;
- (sender as TextBox).Foreground = enable ?
- System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
- }
- private static bool IsTextAllowed(string text)
- {
- Regex regex = new Regex("[^0-9.]+"); //regex that matches disallowed text
- return !regex.IsMatch(text);
- }
- }
- }
|