InputDialogViewModel.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using MECF.Framework.Common.OperationCenter;
  2. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  3. using OpenSEMI.ClientBase;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Globalization;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Input;
  15. namespace MECF.Framework.UI.Client.CenterViews.Dialogs
  16. {
  17. public class RadioButtonIsSelectedConvert : IValueConverter
  18. {
  19. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  20. {
  21. if (value == null)
  22. return false;
  23. bool result = false;
  24. if (value.ToString() == parameter.ToString())
  25. result = true;
  26. else
  27. result = false;
  28. return result;
  29. }
  30. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  31. {
  32. return parameter.ToString();
  33. }
  34. }
  35. public class InputDialogViewModel:DialogViewModel<string>
  36. {
  37. #region Items Property
  38. public int Left { get; set; }
  39. public string Content { get; set; }
  40. public bool IsSelected { get; set; }
  41. public string KeyboardType { get; set; } = "Number";
  42. #endregion
  43. public ConfigItem Item { get; set; }
  44. public ObservableCollection<InputDialogViewModel> SubItems { get; set; } = new ObservableCollection<InputDialogViewModel>();
  45. public Visibility TextVisibility { get; set; }
  46. private const string YesString = "Yes";
  47. private const string NoString = "No";
  48. public string HeaderText
  49. {
  50. get { return "Congfig Set"; }
  51. }
  52. protected override void OnViewLoaded(object view)
  53. {
  54. base.OnViewLoaded(view);
  55. SubItems.Clear();
  56. if(Item.Type ==DataType.Bool)
  57. {
  58. bool bYes = Item.CurrentValue == YesString ? true : false;
  59. SubItems.Add(new InputDialogViewModel() { Content = YesString, IsSelected = bYes, Left = 100 }) ;
  60. SubItems.Add(new InputDialogViewModel() { Content = NoString,IsSelected=!bYes, Left = 200});
  61. }
  62. if (Item.Tag == "ReadOnlySelection")
  63. {
  64. string[] values = Item.Parameter.Split(';');
  65. for (int i = 0; i < values.Length; i++)
  66. {
  67. bool bSelected = Item.CurrentValue == values[i] ? true : false;
  68. SubItems.Add(new InputDialogViewModel() { Content = values[i],IsSelected=bSelected, Left = (i+1) * 60});
  69. }
  70. }
  71. if (SubItems.Count > 0) TextVisibility = Visibility.Hidden;
  72. }
  73. public void OK()
  74. {
  75. //Item.CurrentValue = YesChecked ? "Yes" : "No";
  76. foreach (var item in SubItems)
  77. {
  78. if (item.IsSelected)
  79. Item.CurrentValue = item.Content;
  80. }
  81. if (!string.IsNullOrEmpty(Item.CurrentValue))
  82. {
  83. this.DialogResult = Item.CurrentValue;
  84. IsCancel = false;
  85. TryClose(true);
  86. }
  87. }
  88. public void Cancel()
  89. {
  90. IsCancel = true;
  91. TryClose(false);
  92. }
  93. }
  94. }