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
-
public void addColumn()
-
{
-
LS.Add(
"表下カップ綿天竺仮縫い_37s_C_1");
-
LS.Add(
"上カップマーキしつけ_28s_C_2");
-
LS.Add(
"上下カップ接ぎ_33s_C_3");
-
LS.Add(
"上下カップ押え_62s_B_4");
-
LS.Add(
"カップ脇しつけ_14s_B_5");
-
LS.Add(
"表上カップレース端押さえ_41s_B_6");
-
for (
int i =
0; i < LS.Count; i++)
-
{
-
DataGridTemplateColumn dl =
new DataGridTemplateColumn();
-
-
dl.Header = LS[i];
-
DataTemplate MyDataTemplate =
new DataTemplate();
-
-
Binding binding =
new Binding()
-
{
-
Path =
new PropertyPath(
"Ml.Num" + (i +
1))
// 需绑定的数据源属性名
-
,
-
Mode = BindingMode.TwoWay
// 绑定模式
-
,
-
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
-
};
-
-
var Item =
new FrameworkElementFactory(
typeof(ItemControl));
-
Item.SetBinding(ItemControl.SetRGBProperty, binding);
-
-
-
MyDataTemplate.VisualTree = Item;
-
-
dl.CellTemplate = MyDataTemplate;
-
-
dataGrid.Columns.Add(dl);
-
}
-
}
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 ~ ~