WPF dynamic column (DataGridTemplateColumn) binding data (custom)

Original: WPF dynamic column (DataGridTemplateColumn) binding data (custom)

 

 

Because the project needs to achieve this - 

How to achieve painting red frame content section

Swastika lattice belonging to a custom Textbox above function is generally different colors to obtain a color string and a set value of the last displayed word lattice fields 

This is mainly about DataGridTemplateColumn and the rewrite Datatemplate

Key comments listed separately the

LS is the column of data objects

listName row of data objects

 var Item = new FrameworkElementFactory (typeof ( ItemControl)); // generate custom objects
 Item.SetBinding (ItemControl.SetRGBProperty, binding); // set Bing
 MyDataTemplate.VisualTree = Item; increased visual tree


  
  
  1. public void addColumn()
  2. {
  3. LS.Add( "表下カップ綿天竺仮縫い_37s_C_1");
  4. LS.Add( "上カップマーキしつけ_28s_C_2");
  5. LS.Add( "上下カップ接ぎ_33s_C_3");
  6. LS.Add( "上下カップ押え_62s_B_4");
  7. LS.Add( "カップ脇しつけ_14s_B_5");
  8. LS.Add( "表上カップレース端押さえ_41s_B_6");
  9. for ( int i = 0; i < LS.Count; i++)
  10. {
  11. DataGridTemplateColumn dl = new DataGridTemplateColumn();
  12. dl.Header = LS[i];
  13. DataTemplate MyDataTemplate = new DataTemplate();
  14. Binding binding = new Binding()
  15. {
  16. Path = new PropertyPath( "Ml.Num" + (i + 1)) // 需绑定的数据源属性名
  17. ,
  18. Mode = BindingMode.TwoWay // 绑定模式
  19. ,
  20. UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
  21. };
  22. var Item = new FrameworkElementFactory( typeof(ItemControl));
  23. Item.SetBinding(ItemControl.SetRGBProperty, binding);
  24. MyDataTemplate.VisualTree = Item;
  25. dl.CellTemplate = MyDataTemplate;
  26. dataGrid.Columns.Add(dl);
  27. }
  28. }

Because the background so there is nothing XAML

Want to know how to generate this control can be seen all WPF step by step article knowledge in October 2019 are in can not understand the message

WPF dynamic column (DataGridTemplateColumn) binding data (custom) object is bound to change the subject

Today headache should not stay up late ~ ~

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12075406.html