Exemplo n.º 1
0
        private void SetBinding(XDataGridColumn targetColumn,
                                string srcPath, DependencyProperty targetPrp)
        {
            var binding = new Binding
            {
                Source = this,
                Path   = new PropertyPath(srcPath)
            };

            BindingOperations.SetBinding(targetColumn,
                                         targetPrp, binding);
        }
Exemplo n.º 2
0
        private void LoadColumns(IEnumerable <DataGridColumn> staticColumns, IEnumerable columnSrcs)
        {
            AutoGenerateColumns = false;

            var columns = new List <DataGridColumn>();

            Columns.Clear();

            if (staticColumns != null)
            {
                foreach (var col in staticColumns)
                {
                    columns.Add(col);
                }
            }

            if (columnSrcs != null)
            {
                foreach (var colSrc in columnSrcs)
                {
                    var col = new XDataGridColumn()
                    {
                        Header = colSrc
                    };

                    SetBinding(col, nameof(CellTemplate), XDataGridColumn.CellTemplateProperty);
                    SetBinding(col, nameof(CellEditingTemplate), XDataGridColumn.CellEditingTemplateProperty);
                    SetBinding(col, nameof(CellContentSelector), XDataGridColumn.CellContentSelectorProperty);
                    SetBinding(col, nameof(ColumnHeaderTemplate), DataGridColumn.HeaderTemplateProperty);
                    SetBinding(col, nameof(ColumnHeaderTemplateSelector), DataGridColumn.HeaderTemplateSelectorProperty);
                    SetBinding(col, nameof(CellTemplateSelector), XDataGridColumn.CellTemplateSelectorProperty);
                    SetBinding(col, nameof(CellEditingTemplateSelector), XDataGridColumn.CellEditingTemplateSelectorProperty);

                    if (ColumnVisibilityBinding != null)
                    {
                        BindingOperations.SetBinding(col, XDataGridColumn.VisibilityProperty, ColumnVisibilityBinding);
                    }

                    columns.Add(col);
                }

                ColumnsPreCreated?.Invoke(columns);

                foreach (var column in columns)
                {
                    Columns.Add(column);
                }
            }
        }