Hi,
I have custom content that I would like to display in a fixed row at the bottom of my datagrids. It would be very similar to the SummaryResultsPresenter area, however I don't want it to be fixed to any record columns. It needs to span the entire width of the datagrid and always be fixed as the last row of the datagrid.
We currently define our xamdatagrids in code like this:
------------------------------------------------------------------------------------------------------------
private void OurDataGrid_Loaded(object sender, RoutedEventArgs e){this.myDataGrid = sender as XamDataGrid;OurDataGrid myProjectGrid = sender as OurDataGrid;
Grid grid = Utilities.GetDescendantFromType(this.myDataGrid, typeof(Grid), false) as Grid;
if (grid != null && grid.Children.Count < 2){grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) });
Grid dynamicGrid = new Grid();
RowDefinition gridRow1 = new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) };RowDefinition gridRow2 = new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) };RowDefinition gridRow3 = new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) };RowDefinition gridRow4 = new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) };dynamicGrid.RowDefinitions.Add(gridRow1);dynamicGrid.RowDefinitions.Add(gridRow2);dynamicGrid.RowDefinitions.Add(gridRow3);dynamicGrid.RowDefinitions.Add(gridRow4);
Grid.SetRow(this.lblFilteredItems, 0);dynamicGrid.Children.Add(this.lblFilteredItems);
Grid.SetRow(this.searchBar, 1);dynamicGrid.Children.Add(this.searchBar);
grid.Children.Add(dynamicGrid);
summaryFooterRow.Template = (ControlTemplate)this.TryFindResource("ControlTemplate");Grid.SetRow(this.summaryFooterRow, 3);//grid.Children.Add(this.summaryFooterRow);}
The row I would like to set as fixed to the bottom is called summaryFooterRow. The problem is that the row I am setting above that row (grid.Children.Add(dynamicGrid);) could be 5 or 5,000 rows of data. Right now summaryFooterRow is displaying above the dynamic grid.
Just to be clear, we have a total of 4 rows, (1) a filter row, (2) a searchbox row, (3) the dynamic data rows, and (4) the summaryFooterRow that I am trying to fix to the bottom.
Is there a way to set summaryFooterRow as the 4th row and the dynamicGrid rows as the 3rd row? Or is there a better way to fix it to the bottom of the datagrid than the way I am trying to do it?
Thanks in advance for your help!
-Jeff
Hello Jeff,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
You can try to set the Tag in the constructor of your custom control, because I assume it is too late in the initialize event and the style is already loaded.
Thanks, your example works great, but do you know how I could access it in my custom control from a style?
I have the DataTrigger set like this:
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=Tag}" Value="XDG">
and then in the code behind initialize event of my custom control I have:
this.Tag = "XDG";
But then the style doesn't get applied and the VS output gives me:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.XamDataGrid', AncestorLevel='1''. BindingExpression:Path=Tag; DataItem=null; target element is 'ScrollViewer' (Name=''); target property is 'NoTarget' (type 'Object')
Any idea of how to connect this?
Thanks again!-Jeff
You can add a DataTrigger in the ScrollViewer Style and bind it to the XamDataGrid's Tag. I modified the sample I sent you before. Now the Template will be applied if the ScrollViewer is inside a XamDataGrid with tag set to "XDG".
This works, however, in my scenario I will have numerous controls on the page. I don't want the other controls to inherit this customized style; just my XamDataGrids which are custom controls.
So, is there a way I can call it in the code behind so it will only apply to the XamDataGrids on the page?
Maybe something like this:
xamdatagrid1.scrollviewer.Style = (Style)this.TryFindResource("ScrollViewerSummaryRow");
Thanks!-Jeff