HzOverviewView.xaml.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Text.RegularExpressions;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using Aitex.Core.Account;
  6. using Aitex.Core.UI.MVVM;
  7. using Triton160.UI.ViewModel;
  8. namespace Aitex.Triton160.UI.Views.Hz
  9. {
  10. /// <summary>
  11. /// HzOverviewView.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class HzOverviewView : UserControl
  14. {
  15. private OverviewViewModel _vm;
  16. public HzOverviewView()
  17. {
  18. InitializeComponent();
  19. _vm = new OverviewViewModel(this);
  20. this.DataContext = _vm;
  21. this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(OverviewView_IsVisibleChanged);
  22. this.Loaded += OverviewView_Loaded;
  23. }
  24. void OverviewView_Loaded(object sender, RoutedEventArgs e)
  25. {
  26. OverviewViewModel model = this.DataContext as OverviewViewModel;
  27. this.Name = "overview";
  28. var permission = this.GetPermission();
  29. switch (permission)
  30. {
  31. case ViewPermission.PartlyControl:
  32. //canvasGraphicDevice.IsEnabled = false;
  33. gridMonitorTable.IsEnabled = false;
  34. groupManualOperation.IsEnabled = false;
  35. break;
  36. default:
  37. break;
  38. }
  39. model.IsFullControlPermission = permission == ViewPermission.FullyControl;
  40. }
  41. void OverviewView_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  42. {
  43. (this.DataContext as TimerViewModelBase).EnableTimer(this.IsVisible);
  44. }
  45. private void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  46. {
  47. e.Handled = !IsTextAllowed(e.Text);
  48. }
  49. private void InputTextBoxPower_TextChanged(object sender, TextChangedEventArgs e)
  50. {
  51. double input;
  52. bool enable = true;
  53. if (!double.TryParse((sender as TextBox).Text, out input))
  54. enable = false;
  55. else if (input < 0 || input > _vm.Rf.ScalePower)
  56. enable = false;
  57. (sender as TextBox).Foreground = enable ?
  58. System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
  59. }
  60. private static bool IsTextAllowed(string text)
  61. {
  62. Regex regex = new Regex("[^0-9.]+"); //regex that matches disallowed text
  63. return !regex.IsMatch(text);
  64. }
  65. }
  66. }