Exemplo n.º 1
0
        /// <summary>
        /// ///////////////////////////////////////////////////////////////////////////////////////////
        // DataGridColumn
        //    DataGridComboBoxColumn
        //    DataGridTemplateColumn
        //    DataGridBoundColumn
        //       DataGridCheckBoxColumn
        //       DataGridHyperlinkColumn
        //       DataGridTextColumn
        /// </summary>
        private void CreateDataGridRowDetailsTemplate()
        {
            IList <ColumnData> columns = new List <ColumnData>();

            foreach (DataGridColumn column in this.AssociatedObject.Columns)
            {
                Binding     binding      = null;
                string      path         = String.Empty;
                string      stringFormat = String.Empty;
                IEnumerable comboSource  = new List <string>();

                Type   type   = column.GetType();
                string header = (column.Header == null) ? String.Empty : column.Header.ToString();
                if (column is DataGridBoundColumn)
                {
                    DataGridBoundColumn boundColumn = column as DataGridBoundColumn;
                    binding = boundColumn.Binding as Binding;
                    if (binding != null)
                    {
                        path         = binding.Path.Path;
                        stringFormat = binding.StringFormat;
                    }
                }
                else if (column is Glass.UX.Windows.Controls.DataGridComboBoxColumn)
                {
                    Glass.UX.Windows.Controls.DataGridComboBoxColumn boundColumn = column as Glass.UX.Windows.Controls.DataGridComboBoxColumn;
                    binding = boundColumn.SelectedItemBinding as Binding;
                    if (binding != null)
                    {
                        path        = binding.Path.Path;
                        comboSource = boundColumn.ItemsSource;
                    }
                }
                columns.Add(new ColumnData(type, binding, header, path, stringFormat, comboSource));
            }

            DataTemplate template = new DataTemplate();

            template.VisualTree = this.CreateContainerlElement(columns);

            this.AssociatedObject.RowDetailsTemplate = template;
        }
        //private void LoadData(string columnSet)
        //{
        //	var dataGrid =  TradeLink.DBContext.DBService.Data.DataGridGroups.Expand("DataGridColumns").Where(p => p.Name == columnSet).FirstOrDefault();
        //	this.CreateColumn(dataGrid);
        //}

        //private void CreateColumn(DataGridGroup dataGrid)
        //{
        //	var dgcg = new DataGridColumnGen();
        //	foreach (var column in dataGrid.DataGridColumns)
        //	{
        //		dgcg.Width = column.Width;
        //		dgcg.Type = column.Type;
        //		dgcg.Sequence = column.Sequence;
        //		dgcg.UpdateTriggerId = column.UpdateTriggerId;
        //		dgcg.HasFilter = column.HasFilter;
        //		dgcg.Header = column.Header;
        //		dgcg.Path = column.Path;
        //		dgcg.Format = column.Format;
        //		dgcg.CellTemplate = column.CellTemplate;
        //		dgcg.CellStyle = column.CellStyle;
        //		if (column.Binding_Id.HasValue)
        //			dgcg.Binding_Id = column.Binding_Id.Value;

        //		this.GenerateDataGridColumn(dgcg);
        //	}
        //}

        public void GenerateDataGridColumn(DataGridColumnGen column)
        {
            System.Windows.Controls.DataGridColumn col = null;

            switch (column.Type)
            {
            case 1:        //Text
                col = new Glass.UX.Windows.Controls.DataGridTextColumn();
                break;

            case 2:        //Combo
                col = new Glass.UX.Windows.Controls.DataGridComboBoxColumn();
                break;

            case 3:        //Check
                col = new Glass.UX.Windows.Controls.DataGridCheckBoxColumn();
                break;

            case 4:        //Numeric
                col = new DataGridNumericColumn();
                break;

            case 5:        //Currency
                col = new DataGridNumericColumn();
                break;

            case 6:        //Date
                col = new DataGridDateColumn();
                break;

            case 7:        //Template
                col = new DataGridTemplateColumn();
                ((DataGridTemplateColumn)col).CellTemplate = AssociatedObject.TryFindResource(column.CellTemplate) as DataTemplate;
                break;

            case 8:        //Details
                col       = new DataGridDetailColumn();
                col.Width = column.Width;
                break;
            }

            if (col != null)
            {
                Binding binding = null;
                if (!String.IsNullOrEmpty(column.Path))
                {
                    binding = new Binding(column.Path);
                }
                if (!String.IsNullOrEmpty(column.Format) && binding != null)
                {
                    binding.StringFormat = column.Format;
                }
                if (!String.IsNullOrEmpty(column.Header))
                {
                    col.Header = column.Header;
                }
                if (!String.IsNullOrEmpty(column.CellStyle))
                {
                    col.CellStyle = AssociatedObject.TryFindResource(column.CellStyle) as Style;
                }

                if (column.HasFilter)
                {
                    col.HeaderStyle = Application.Current.Resources["DataGridColumnFilterHeaderStyle"] as Style;
                }

                if (col is DataGridBoundColumn)
                {
                    ((DataGridBoundColumn)col).Binding = binding;
                }
                AssociatedObject.Columns.Add(col);
            }
        }