【问题标题】:WPF DataGrid: Problem with showing DisplayNameAttribute valuesWPF DataGrid:显示 DisplayNameAttribute 值的问题
【发布时间】:2011-03-02 19:05:06
【问题描述】:

为什么 WPF DataGrid 控件不显示为网格列定义的 DisplayNameAttribute 值?但是,当使用 Winforms DataGridView 时,这可以正常工作!

非常感谢;)

【问题讨论】:

    标签: wpf datagrid


    【解决方案1】:

    它在 WPF 中不起作用。您可能会争辩说这是关于保持 View 和 Model 数据的分离。

    解决您的问题的最简单方法是提前定义列;与将 AutoGenerateColumns 设置为 true 相比。

    <toolkit:DataGridTextColumn Header="{x:Static const:Resources.ScriptNameHeader_String}" Binding="{Binding Name}"/>
    

    【讨论】:

    • 我使用原生 wpf DataGrid 控件,所以我认为我应该使用 wpf 工具包的 DataGrid 控件。你用那个吗?支持吗?
    • @Sadegh 我在 .NET 3.5 SP1 上,所以我使用的是 WPF Toolkit DataGrid,它应该与移入 .NET 4 的 DataGrid 相同。我的示例应该使用 .NET 4 DataGrid AFAIK。
    • 目前我正在使用.NET 4!我的问题是关于 DisplayName、Browsable 等的支持;不是关于你的方法。谢谢亚伦
    • 我很好奇为什么 WPF DataGrid 不支持这个功能!手动定义列是不好的!我有多达 30 个窗口,所有这些都有自己的 DataGrid!
    • 手动定义它们是什么意思?它们可以是我所做的资源,因此可以全局访问,或者您可以将 AutoGenerateColumns 设置为 true 而不必设置任何内容。
    猜你喜欢
    • 2013-08-29
    • 1970-01-01
    • 2013-06-16
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 2011-05-04
    相关资源
    最近更新 更多