我需要将我的 UserControl 添加到 WPF 中的 DataGridCells。我在我的代码中将数据绑定(bind)到 DataGrid,而不是在 XAML 中。那么如何在代码中而不是在 XAML 中执行此操作?
最佳答案
您的问题是关于 DataGrid 还是 UserControl?
据我了解,每个 DataGrid 行中都有一个 UserControl。或者我们可以说,UserControl 的父级是一个 DataGrid 元素,DataGrid 的绑定(bind)是在代码中完成的。
无论 DataGrid(而非 DataGridCell)的数据绑定(bind)是在代码中还是在 XAML 中定义,您唯一需要考虑的是所包含元素(UserControl)影响的每一行的数据。
所以,你只需要考虑“如何在UserControl中显示每条数据”,与DataGrid无关。
要在 DataGridCell 中添加 UserControl,此链接将为您提供很好的引用:http://www.wpftutorial.net/DataGrid.html
关于c# - 将 UserControl 添加到 WPF DataGrid 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8035072/