如何确定 WPF DataGrid 中的基本类型(使用 AutoGenerateColumn 时)?
当使用 AutoGenerateColumn 创建控件时,如何确定 DataGrid 控件绑定列的原始类型?
我查看了所有这些类:DataGridColumn
、DataGridBoundColumn
、DataGridTextColumn
和 DataGridBoundColumn.Binding
。
我无法确定列绑定到哪种类型(原始类型)。 (它们绑定到 SQL 表。)我想根据类型应用不同的样式和转换器。我可以根据列名称(我可以从 DataGridTextColumn.Header 获得)对这些样式和转换器进行硬编码,但我想不惜一切代价避免这种情况!
How can I determine the primitive Type of the bound column to a DataGrid control, when the control is created using AutoGeneratingColumn?
I have looked in all these classes: DataGridColumn
, DataGridBoundColumn
, DataGridTextColumn
, and DataGridBoundColumn.Binding
.
I am unable to determine which Type (primitive type) the columns are bound to. (They are Bound to a SQL table.) I want to apply different styles and converters based on the type. I could Hard Code these styles and converters based on the column name (which I can get from DataGridTextColumn.Header
), but I want to AVOID THAT AT ALL COSTS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我找到了答案。
该类型作为 e.PropertyType 传递到“AutoGenerateColumn”处理程序中。
问题是,这不是真正的类型。它必须被装箱,因为即使数据库列是“可为空的”,但传递的类型却不是。
因此,我将不得不根据列名称对我的解决方案进行“硬编码”。 :(
Looks like I found the answer.
The type is passed into the "AutoGeneratingColumn" handler as e.PropertyType.
The problem is, it isn't the real type. It must be boxed, because even though the database column is "nullable" the type passed isn't.
So, I am going to have to "Hard Code" my solution, based on Column Name. :(