简体   繁体   English

如何在datagrid中添加列

[英]How to add column in datagrid

How i can add column in wpf toolkit datagrid from code behind? 我怎样才能从后面的代码在WPF工具包DataGrid中添加列? this does not works: 这不起作用:

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

this is my grid : 这是我的网格:

 <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>

WPF 4 has its own DataGrid, the column you created is from that namespace, it is not compatible with the Toolkit-DataGrid. WPF 4有其自己的DataGrid,您创建的列是从该名称空间来的,它与Toolkit-DataGrid不兼容。 If you use WPF 4 you probably should not use the Toolkit DataGrid at all. 如果使用WPF 4,则可能根本不应该使用Toolkit DataGrid。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM