【问题标题】:How to add column in datagrid如何在数据网格中添加列
【发布时间】:2011-10-16 20:29:27
【问题描述】:

如何从后面的代码中添加 wpf 工具包数据网格中的列? 这不起作用:

DataGridTemplateColumn txtc = new DataGridTemplateColumn();
        txtc.Header = "2";
        myGrid.Columns.Add(txtc);

这是我的网格:

 <Controls:DataGrid.CellStyle>
            <Style TargetType="{x:Type Controls:DataGridCell}">
                <Setter Property="Background">
                    <Setter.Value>
                        <MultiBinding Converter="{StaticResource myHighlighterConverter}">
                            <MultiBinding.Bindings>
                                <Binding RelativeSource="{RelativeSource Self}"></Binding>
                                <Binding Path="Row"></Binding>
                            </MultiBinding.Bindings>
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </Style>
        </Controls:DataGrid.CellStyle>
    </Controls:DataGrid>

【问题讨论】:

    标签: c# wpf xaml datagrid wpftoolkit


    【解决方案1】:

    WPF 4 有自己的 DataGrid,您创建的列来自该命名空间,它与 Toolkit-DataGrid 不兼容。如果您使用 WPF 4,您可能根本不应该使用 Toolkit DataGrid。

    【讨论】:

    • 我知道,但即使 vs 给出这样的错误,它也不会添加列:错误 2 参数 1:无法从 'System.Windows.Controls.DataGridTemplateColumn' 转换为 'Microsoft.Windows.Controls.DataGridColumn跨度>
    • @Acid:那你为什么不在血淋淋的问题中加上错误呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    • 2011-09-22
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多