MainWindow.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using WPfPointInfo.InfoProperty;
  17. namespace WPfPointInfo
  18. {
  19. /// <summary>
  20. /// MainWindow.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. public MainWindow()
  25. {
  26. InitializeComponent();
  27. this.Loaded += MainWindow_Loaded;
  28. }
  29. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  30. {
  31. try
  32. {
  33. InfoGrid.ItemTemplateSelector = new CommonAssigmentSelector();
  34. InfoGrid.ItemsSource = CreateDatas();
  35. // InfoGrid.NameColumnWidth = 250;
  36. }
  37. catch (Exception ex)
  38. {
  39. // throw;
  40. }
  41. }
  42. private ObservableCollection<ItemProperty> CreateDatas()
  43. {
  44. ObservableCollection<ItemProperty> properties = new ObservableCollection<ItemProperty>();
  45. for (int i = 0; i < 3; i++)
  46. {
  47. ItemProperty level1 =new ItemProperty(){Definition= PropertyDefinition.CreateCagetoryDefinition()};
  48. level1.Value = "分类" + (i + 1);
  49. #region 二层
  50. for (int j = 0; j < 4; j++)
  51. {
  52. ItemProperty level2 = new ItemProperty() { Definition = PropertyDefinition.CreateCagetoryDefinition() };
  53. level2.Value = "分类" + (j + 1);
  54. for (int k = 0; k < 5; k++)
  55. {
  56. //Enum_D1;Textbox_DoubleUnit_A2
  57. var definition = new PropertyDefinition() {EditId = "Enum_D1" };
  58. AssigmentItemProperty property = new AssigmentItemProperty() { Definition = definition };
  59. property.Definition.DisplayName="信息点"+(k+1);
  60. property.Value = k;
  61. property.ExtendObject = new TestExtend();
  62. #region 多个值
  63. for (int l = 0; l < 2; l++)
  64. {
  65. var childDefinnition = definition.Clone();
  66. childDefinnition.ReadOnly = true;
  67. childDefinnition.Enabled = false;
  68. ItemProperty valueProperty = new ItemProperty() { Definition = childDefinnition };
  69. valueProperty.Value = (l % 2) + 1;
  70. valueProperty.ExtendObject = new TestExtend();
  71. property.AlternativeProperties.Add(valueProperty);
  72. }
  73. #endregion
  74. level2.Children.Add(property);
  75. }
  76. level1.Children.Add(level2);
  77. }
  78. #endregion
  79. properties.Add(level1);
  80. }
  81. return properties;
  82. }
  83. public class TestExtend
  84. {
  85. public TestExtend()
  86. {
  87. Unit = "m";
  88. EnumItems=new List<NameValueItem>(){new NameValueItem(){Name = "第一项",Value = "1"}, new NameValueItem() { Name = "第二项", Value = "2" } };
  89. }
  90. /// <summary>
  91. /// 单位
  92. /// </summary>
  93. public string Unit { set; get; }
  94. public List<NameValueItem> EnumItems { get; set; }
  95. }
  96. public class NameValueItem
  97. {
  98. public string Name { get; set; }
  99. public string Value { get; set; }
  100. public override string ToString()
  101. {
  102. return Name?.ToString();
  103. }
  104. }
  105. }
  106. }