终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ItemsList.cs 1.6 KiB

2 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Microsoft.Toolkit.Mvvm.Input;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace BPASmartClient.SCADAControl.Converters
  9. {
  10. /// <summary>
  11. /// 因ObservableCollection无法序列化,继承并实例化一个
  12. /// </summary>
  13. public class ItemsList : ObservableCollection<string>
  14. {
  15. public ItemsList()
  16. {
  17. AddCommand = new RelayCommand<string>(AddItem);
  18. DeleteCommand = new RelayCommand<string>(DeleteItem);
  19. }
  20. private void DeleteItem(string obj)
  21. {
  22. if (!string.IsNullOrEmpty(obj))
  23. Remove(obj);
  24. }
  25. public RelayCommand<string> AddCommand { get; }
  26. public RelayCommand<string> DeleteCommand { get; }
  27. private void AddItem(string txt)
  28. {
  29. if (!string.IsNullOrEmpty(txt))
  30. Add(txt);
  31. }
  32. }
  33. public class ItemsListObj:ObservableCollection<object>
  34. {
  35. public ItemsListObj()
  36. {
  37. AddCommand = new RelayCommand<object>(AddItem);
  38. DeleteCommand = new RelayCommand<object>(DeleteItem);
  39. }
  40. private void DeleteItem(object obj)
  41. {
  42. if (obj!=null)
  43. Remove(obj);
  44. }
  45. public RelayCommand<object> AddCommand { get; }
  46. public RelayCommand<object> DeleteCommand { get; }
  47. private void AddItem(object txt)
  48. {
  49. if (txt != null)
  50. Add(txt);
  51. }
  52. }
  53. }