简体   繁体   English

您如何在C#中以编程方式为WPF工具包datagrid创建列?

[英]How do you create columns programmatically in C# for a WPF toolkit datagrid?

I have seen many examples of creating a WPF Toolkit DataGrid in XAML and it is possible to write certain tags and there will be some columns, rows, etc depending on what you wrote. 我已经看到了许多在XAML中创建WPF Toolkit DataGrid的示例,并且可以编写某些标签,并且根据您编写的内容将有一些列,行等。

Lets say I have an empty (it has no columns, no rows, nothing) WPF Toolkit DataGrid that has been created in XAML how do I add columns in C# programmatically ( not in XAML )? 可以说我有一个空的(没有列,没有行,什么也没有)在XAML中创建的WPF Toolkit DataGrid我如何以编程方式在C#中添加列( 不在XAML中 )?

Thank you for any help! 感谢您的任何帮助!

This should work for you. 这应该为您工作。

MyDataGrid.Columns.Add(new DataGridTextColumn()
{
    Header="MyHeader", 
    Binding=new Binding("MyProperty")
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM