| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using WPfPointInfo.InfoProperty;
- namespace WPfPointInfo
- {
- /// <summary>
- /// MainWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- this.Loaded += MainWindow_Loaded;
- }
- private void MainWindow_Loaded(object sender, RoutedEventArgs e)
- {
- try
- {
- InfoGrid.ItemTemplateSelector = new CommonAssigmentSelector();
- InfoGrid.ItemsSource = CreateDatas();
- // InfoGrid.NameColumnWidth = 250;
- }
- catch (Exception ex)
- {
- // throw;
- }
- }
- private ObservableCollection<ItemProperty> CreateDatas()
- {
- ObservableCollection<ItemProperty> properties = new ObservableCollection<ItemProperty>();
- for (int i = 0; i < 3; i++)
- {
- ItemProperty level1 =new ItemProperty(){Definition= PropertyDefinition.CreateCagetoryDefinition()};
- level1.Value = "分类" + (i + 1);
- #region 二层
- for (int j = 0; j < 4; j++)
- {
- ItemProperty level2 = new ItemProperty() { Definition = PropertyDefinition.CreateCagetoryDefinition() };
- level2.Value = "分类" + (j + 1);
- for (int k = 0; k < 5; k++)
- {
- //Enum_D1;Textbox_DoubleUnit_A2
- var definition = new PropertyDefinition() {EditId = "Enum_D1" };
- AssigmentItemProperty property = new AssigmentItemProperty() { Definition = definition };
- property.Definition.DisplayName="信息点"+(k+1);
- property.Value = k;
- property.ExtendObject = new TestExtend();
- #region 多个值
- for (int l = 0; l < 2; l++)
- {
- var childDefinnition = definition.Clone();
- childDefinnition.ReadOnly = true;
- childDefinnition.Enabled = false;
- ItemProperty valueProperty = new ItemProperty() { Definition = childDefinnition };
- valueProperty.Value = (l % 2) + 1;
- valueProperty.ExtendObject = new TestExtend();
- property.AlternativeProperties.Add(valueProperty);
- }
- #endregion
- level2.Children.Add(property);
- }
- level1.Children.Add(level2);
- }
- #endregion
- properties.Add(level1);
- }
- return properties;
- }
- public class TestExtend
- {
- public TestExtend()
- {
- Unit = "m";
- EnumItems=new List<NameValueItem>(){new NameValueItem(){Name = "第一项",Value = "1"}, new NameValueItem() { Name = "第二项", Value = "2" } };
- }
- /// <summary>
- /// 单位
- /// </summary>
- public string Unit { set; get; }
- public List<NameValueItem> EnumItems { get; set; }
- }
- public class NameValueItem
- {
- public string Name { get; set; }
- public string Value { get; set; }
- public override string ToString()
- {
- return Name?.ToString();
- }
- }
- }
- }
|