/// <summary> /// Adds an almost blank row(row with bare minimum data) to the list of rows. /// </summary> /// <param name="dataContext">The Data Context for the row.</param> public void AddBlank(object dataContext) { DataBoundRow tempRow = new DataBoundRow(this.lastRow); tempRow.HostingWrapDataGrid = this.HostingWrapDataGrid; tempRow.Visibility = Visibility.Visible; tempRow.DataContext = dataContext; bool addHeaderIntoPanel = false; DataBoundRowGrouping grouping = null; if (null != this.groupingTemplateLogic) { grouping = DataTemplateHelper.LoadContent(this.groupingTemplateLogic) as DataBoundRowGrouping; if (null != grouping) { grouping.DataSource = dataContext; tempRow.Grouping = grouping; if (null == this.lastRow) { // new header as we are the first row and we have a grouping template addHeaderIntoPanel = true; } else { if (this.lastRow.Grouping.GroupingText != tempRow.Grouping.GroupingText) { // we have a grouping template and we are not the same as the last row. addHeaderIntoPanel = true; } } // Update the groupings hash table. if (this.hashGroupings.ContainsKey(tempRow.Grouping.GroupingText)) { Collection <DataBoundRow> groupedRows = this.hashGroupings[tempRow.Grouping.GroupingText]; groupedRows.Add(tempRow); } else { Collection <DataBoundRow> groupedRows = new Collection <DataBoundRow>(); groupedRows.Add(tempRow); this.hashGroupings.Add(tempRow.Grouping.GroupingText, groupedRows); } } } // Indicates this row contains group header if (addHeaderIntoPanel && this.lastRow != null) { this.RaiseGroupingRenderEvent(); } foreach (ColumnManager column in this.columns) { if (this.rightToLeft) { column.StackPanel.Children.Insert(0, new StackPanel()); } else { column.StackPanel.Children.Add(new StackPanel()); } } tempRow.Index = this.rows.Count; tempRow.IsBlank = true; this.lastRow = tempRow; this.rows.Add(tempRow); }
/* * /// <summary> * /// ColumnManagers collection. * /// </summary> * /// <param name="dictionary">The resources ResourceDictionary.</param> * /// <returns>The collection of ColumnManagers.</returns> * public static Collection<ColumnManager> ColumnManagers(ResourceDictionary dictionary) * { * Collection<ColumnManager> collection = new Collection<ColumnManager>(); * foreach (object item in dictionary.Values) * { * ColumnManager manager = item as ColumnManager; * if (null != manager) * { * collection.Add(manager); * } * } * * return collection; * }*/ #endregion #region Public Methods /// <summary> /// Adds a row to the ColumnView. /// </summary> /// <param name="dataContext">The bound DataContext.</param> /// <returns>True if row was added successfully.</returns> public bool AddRow(object dataContext) { DataBoundRow row = new DataBoundRow(this.lastRow); row.HostingWrapDataGrid = this.HostingWrapDataGrid; row.Visibility = Visibility.Visible; row.DataContext = dataContext; bool addHeaderIntoPanel = false; DataBoundRowGrouping grouping = null; FrameworkElement groupingPresentation = null; if (null != this.groupingTemplateLogic) { grouping = DataTemplateHelper.LoadContent(this.groupingTemplateLogic) as DataBoundRowGrouping; if (null != grouping) { grouping.DataSource = dataContext; row.Grouping = grouping; if (null == this.lastRow) { // new header as we are the first row and we have a grouping template addHeaderIntoPanel = true; } else { if (this.lastRow.Grouping.GroupingText != row.Grouping.GroupingText) { // we have a grouping template and we are not the same as the last row. addHeaderIntoPanel = true; } } // Update the groupings hash table. if (this.hashGroupings.ContainsKey(row.Grouping.GroupingText)) { Collection <DataBoundRow> groupedRows = this.hashGroupings[row.Grouping.GroupingText]; groupedRows.Add(row); } else { Collection <DataBoundRow> groupedRows = new Collection <DataBoundRow>(); groupedRows.Add(row); this.hashGroupings.Add(row.Grouping.GroupingText, groupedRows); } } } // Indicates this row contains group header if (addHeaderIntoPanel && this.lastRow != null) { this.RaiseGroupingRenderEvent(); } this.lastRow = row; bool addGroupingTitle = true; bool bindHeights = false; if (this.columns.Count > 1) { bindHeights = true; } foreach (ColumnManager column in this.columns) { cellId++; Panel dataTemplate = this.LoadContent(column) as Panel; dataTemplate.SetValue(FrameworkElement.NameProperty, String.Format(System.Globalization.CultureInfo.CurrentCulture, WrapDataGridResources.CellNameFormat, cellId)); if (null == dataTemplate) { throw new ArgumentException(WrapDataGridResources.InvalidCellTemplateRootElement); } StackPanel heightController = new StackPanel(); heightController.Orientation = Orientation.Vertical; ToolTip currentTooltip = new ToolTip(); dataTemplate.DataContext = dataContext; if (column.ToolTipTemplate != null) { FrameworkElement tooltipElement = column.ToolTipTemplate.LoadContent() as FrameworkElement; tooltipElement.DataContext = dataContext; if (tooltipElement != null) { if (tooltipElement.GetType().ToString() == "System.Windows.Controls.ContentControl") { tooltipElement.Height = row.Height; tooltipElement.Width = column.Width; } currentTooltip.Content = tooltipElement; } if (currentTooltip != null) { ToolTipService.SetToolTip(heightController, currentTooltip); } } dataTemplate.Tag = string.Format(System.Globalization.CultureInfo.CurrentCulture, WrapDataGridResources.CellTagFormat, this.rows.Count, this.columns.Count - 1); if (this.RightToLeft == true) { column.StackPanel.Children.Insert(0, dataTemplate); } else { if (true == addHeaderIntoPanel) { groupingPresentation = DataTemplateHelper.LoadContent(this.groupingTemplatePresentation) as FrameworkElement; if (null != groupingPresentation) { #if SILVERLIGHT if (null != WrapDataGridResources.GroupButtonName && null != WrapDataGridResources.GroupButtonName && null != groupingPresentation.FindName(WrapDataGridResources.GroupButtonName)) { Button hitButton = groupingPresentation.FindName(WrapDataGridResources.GroupButtonName) as Button; hitButton.IsTabStop = false; } TextBlock groupTitle = groupingPresentation.FindName(WrapDataGridResources.GroupTitleName) as TextBlock; #else // ADDED as FindName is not functioning in the WPF version TextBlock groupTitle = (groupingPresentation as Grid).Children[1] as TextBlock; #endif if (groupTitle == null) { throw new ArgumentNullException(WrapDataGridResources.NoGroupTitleElementFound); } ////only add the title to the first column if (addGroupingTitle) { groupTitle.Text = row.Grouping.GroupingText; this.groupingTitles.Add(groupTitle); row.GroupingHeader = groupingPresentation; #if SILVERLIGHT if (null != WrapDataGridResources.GroupButtonName && null != groupingPresentation.FindName(WrapDataGridResources.GroupButtonName)) { Button hitButton = groupingPresentation.FindName(WrapDataGridResources.GroupButtonName) as Button; hitButton.IsTabStop = true; } #endif } groupingPresentation.MouseLeftButtonDown += new MouseButtonEventHandler(this.GroupingPresentation_MouseLeftButtonDown); groupingPresentation.SetValue(Grid.TagProperty, row.Grouping.GroupingText); groupingPresentation.SetValue(Grid.NameProperty, WrapDataGridResources.GroupingPresentationName); #if !SILVERLIGHT if (addGroupingTitle) { groupingPresentation.UpdateLayout(); } #endif dataTemplate.Children.Add(groupingPresentation); addGroupingTitle = false; } } heightController.Children.Add(dataTemplate); column.StackPanel.Children.Add(heightController); } if (true == bindHeights) { System.Windows.Data.Binding binding = new System.Windows.Data.Binding(WrapDataGridResources.RowHeightPropertyName); binding.Source = row; heightController.SetBinding(StackPanel.HeightProperty, binding); dataTemplate.Loaded += new RoutedEventHandler(this.DataTemplate_Loaded); dataTemplate.SizeChanged += new SizeChangedEventHandler(this.DataTemplate_SizeChanged); row.List.Add(heightController); this.hashCells.Add(dataTemplate.Name, row); } } row.Index = this.rows.Count; this.rows.Add(row); return(true); }