Xceed DataGridControl如何隐藏groupdescription中的列?

时间:2014-04-03 19:54:39

标签: c# wpf xaml wpftoolkit xceed-datagrid

当它是GroupDescription时,我正试图隐藏DataGridControl中的列。有一些简单的方法可以做到这一点,我不知道吗?

列的Visible属性似乎是一个很好的起点,但是我无法弄清楚我可以绑定到XAML的行为,因为它表现得像我想要的那样。

1 个答案:

答案 0 :(得分:0)

如果有人有兴趣,我就是这样做的:

public class CustomDataGridControl : DataGridControl
{
    public CustomDataGridControl()
    {
        var groupLevelDescriptions = (INotifyCollectionChanged)this.GroupLevelDescriptions;
        groupLevelDescriptions.CollectionChanged += collectionChanged_CollectionChanged;
    }

    void collectionChanged_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        { 
            foreach (var item in e.NewItems)
            {
                var groupLevelDescription = item as GroupLevelDescription;

                foreach (var column in this.Columns)
                {
                    if (column.FieldName == groupLevelDescription.FieldName)
                        column.Visible = false;
                }
            }
        }

        if (e.OldItems != null)
        {
            foreach (var item in e.OldItems)
            {
                var groupLevelDescription = item as GroupLevelDescription;

                foreach (var column in this.Columns)
                {
                    if (column.FieldName == groupLevelDescription.FieldName)
                        column.Visible = true;
                }
            }
        }
    }
}