/// <summary> /// Converts the specified value to the target type. /// </summary> /// <param name="value">Input value to convert.</param> /// <param name="targetType">Desired target type.</param> /// <param name="parameter">Conversion parameters.</param> /// <param name="culture">Culture settings.</param> /// <returns>The converted type.</returns> public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null && parameter != null) { if (value.GetType() != typeof(System.Collections.Generic.Dictionary <string, string>)) { throw new System.ArgumentException("This value converter can only convert Dictionary Items of string string type."); } if (parameter.GetType() != typeof(string)) { throw new System.ArgumentException("The parameter for the converter was not specified. Please specify Key name as ConverterParameter"); } Dictionary <string, string> dictionary; dictionary = value as Dictionary <string, string>; if (null != dictionary) { string templateName = dictionary[(string)parameter]; object o = System.Windows.Application.Current.Resources[templateName]; System.Windows.DataTemplate dt = o as System.Windows.DataTemplate; return(DataTemplateHelper.LoadContent(dt)); } } return(null); }
/// <summary> /// Loads the template content for a cell in look ahead/look behind view. /// </summary> /// <param name="column">Template column.</param> /// <returns>UIElement to be loaded into the cell.</returns> private static UIElement LoadViewContent(ColumnManager column) { Grid cellTemplate = DataTemplateHelper.LoadContent(column.MasterCellTemplate) as Grid; UIElement customLookAheadCellTemplate = DataTemplateHelper.LoadContent(column.CellTemplate) as UIElement; cellTemplate.Children.Add(customLookAheadCellTemplate); return(cellTemplate); }
/// <summary> /// Updates the summary for Look ahead/behind columns. /// </summary> /// <param name="dataContext">The data context for summary.</param> /// <param name="rowIndex">Row index for the current binding.</param> /// <param name="behindSummary">Specifies if the summary is for look behind or not.</param> internal void UpdateSummary(object dataContext, int rowIndex, bool behindSummary) { if (this.columns.Count > 0 && this.columns[0].SummaryManager != null) { SummaryManager summaryManager = this.columns[0].SummaryManager; Panel dataTemplate; if (summaryManager.MainPanel.Children.Count == 0) { object templateObject = DataTemplateHelper.LoadContent(summaryManager.CellTemplate); dataTemplate = templateObject as Panel; dataTemplate.DataContext = dataContext; summaryManager.MainPanel.Children.Insert(0, dataTemplate); } else { dataTemplate = summaryManager.MainPanel.Children[0] as Panel; dataTemplate.DataContext = dataContext; } dataTemplate.Tag = String.Format(System.Globalization.CultureInfo.CurrentCulture, WrapDataGridResources.SummaryCellTemplateTagFormat, rowIndex + (behindSummary ? -1 : 1)); } }
/// <summary> /// Loads the template content for a cell in main view. /// </summary> /// <param name="column">Template column.</param> /// <returns>UIElement to be loaded into the cell.</returns> private static UIElement LoadMainViewContent(ColumnManager column) { UIElement customCellTemplate; if (column.MasterCellTemplate == null) { customCellTemplate = DataTemplateHelper.LoadContent(column.CellTemplate) as UIElement; return(customCellTemplate); } Grid cellTemplate = DataTemplateHelper.LoadContent(column.MasterCellTemplate) as Grid; customCellTemplate = DataTemplateHelper.LoadContent(column.CellTemplate) as UIElement; if (column.BodyMargin != null) { customCellTemplate.SetValue(Canvas.MarginProperty, column.BodyMargin); } customCellTemplate.SetValue(Grid.ColumnProperty, 0); customCellTemplate.SetValue(Grid.RowProperty, 1); cellTemplate.Children.Add(customCellTemplate); return(cellTemplate); }
/// <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> /// Adds complete data to a blank row (row with partially filled data) created earlier. /// </summary> /// <param name="position">Position of the Blank Row.</param> public void FillBlankRowWithData(int position) { DataBoundRow row = this.rows[position]; object dataContext = row.DataContext; //// retrieve the data context stored earlier in the row. FrameworkElement groupingPresentation = null; bool addHeaderIntoPanel = false; // if this is not the first row, get the previous row's reference if (position > 0) { this.lastRow = this.rows[position - 1]; } if (null != this.groupingTemplateLogic) { 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; } } } // 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; } int replacePositionForRightToLeft = 0; 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; dataTemplate.Tag = string.Format(System.Globalization.CultureInfo.CurrentCulture, WrapDataGridResources.CellTagFormat, position, this.columns.Count - 1); 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); } } if (this.RightToLeft == true) { //// Actual replace position is calculated as below, since this is a Right to Left Type replacePositionForRightToLeft = this.rows.Count - 1 - position; if (replacePositionForRightToLeft < column.StackPanel.Children.Count) { column.StackPanel.Children.RemoveAt(replacePositionForRightToLeft); column.StackPanel.Children.Insert(replacePositionForRightToLeft, dataTemplate); } } else { if (true == addHeaderIntoPanel) { groupingPresentation = DataTemplateHelper.LoadContent(this.groupingTemplatePresentation) as FrameworkElement; if (null != groupingPresentation) { #if SILVERLIGHT if (null != groupingPresentation && 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); groupingPresentation.UpdateLayout(); #if !SILVERLIGHT if (addGroupingTitle) { groupingPresentation.UpdateLayout(); } #endif dataTemplate.Children.Add(groupingPresentation); dataTemplate.UpdateLayout(); addGroupingTitle = false; } } heightController.Children.Add(dataTemplate); // column.StackPanel.Children.Add(heightController); column.StackPanel.Children.RemoveAt(position); column.StackPanel.Children.Insert(position, 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 = position; row.IsBlank = false; }
/* * /// <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); }