如何在wpf datagrid列中通过C#设置X:Name属性

时间:2013-07-31 09:41:57

标签: c# wpfdatagrid wpf-4.0

在WPF Datagrid中,我动态添加Column,我想通过C#设置DataGrid列的X:Name属性

我的代码:

DataGridTextColumn clm = new DataGridTextColumn();
                    clm.Header = "Marks";
                    clm.Width = 100;
                    clm.IsReadOnly = false;
                    dgChapters.Columns.Add(clm);

如何通过C#

在DataGridTextColumn上设置X:Name属性

1 个答案:

答案 0 :(得分:3)

//Registe it in a Method of a Window class
this.RegisterName("mark", clm);
//Use it in another Method like this
DataGridTextColumn clm2 = this.FindName("mark") as DataGridTextColumn;