c# - 将 UserControl 添加到 WPF DataGrid 单元格

标签 c# .net wpf user-controls

我需要将我的 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/

相关文章:

c# - FTPWeb 请求.NET 3.5 与 4

.net - WinForms 4K 和 1080p 缩放/高 DPI?

.net - ToString() 返回空值?

C#:BackgroundWorker 克隆资源?

c# - 从多个表中选择最大日期

c# - 是否可以在多个项目之间共享 ResourceDictionary 文件?

c# - DataGrid 具有 WPF 中第 n 级单元格的 DataGrid

c# - 从 .NET 应用程序和附件执行服务启动进程

c# - 高性能的属性访问和可能的动态编译

c# - 什么是不断变化的表格表示的最佳集合类型