Exemple #1
0
        // 重置列信息
        private void _ResetColumns(IEnumerable cloumns)
        {
            this.grid.Columns.Clear();
            if (cloumns == null)
            {
                return;
            }
            DataTemplate template = null;

            foreach (IGridViewColumn c in cloumns)
            {
                DevExpress.Xpf.Grid.GridColumn column = new DevExpress.Xpf.Grid.GridColumn();
                column.Header = c.Header;
                column.Width  = c.Width;
                if (c.IsSort && !c.FieldName.IsNullOrEmptyOrWhiteSpace())
                {
                    column.FieldName = c.FieldName;
                }
                DataTemplate temp = null;
                IGridViewCellTemplateProvider _proverder = null;
                foreach (IGridViewCellTemplateProvider proverder in this._providers)
                {
                    temp = proverder.CreateCellTemplate(c);
                    if (temp != null)
                    {
                        template   = temp;
                        _proverder = proverder;
                    }
                }
                if (_proverder == null || template == null)
                {
                    throw new Exception("No suitable proverder.");
                }
                column.CellTemplate = template;
                column.Tag          = c;
                c.Column            = column;
                Binding binding = new Binding();
                binding.Source = c;
                binding.Path   = new PropertyPath("IsVisible");
                column.SetBinding(GridColumn.VisibleProperty, binding);
                this.grid.Columns.Add(column);
            }
        }