1

Topic: Total row (footer) for standard WPF DataGrid

I will simply leave it here, can to whom it is useful.
with speculations and samples,  the various strongly confused candidate solutions of the task of creation of a line for DataGrid which would be always below, found in my opinion the simple and refined decision. 

public class ListCollectionViewWithFooterElement: ListCollectionView
{
public object LastElement {get; set;}
public ListCollectionViewWithFooterElement (IList list, object lastElement): base (list)
{
LastElement = lastElement;
}
public override int Count => base. Count + 1;
public override object GetItemAt (int index)
{
return index == base. Count? LastElement: base. GetItemAt (index);
}
}

The criticism is welcomed.
Theoretically, it would be necessary to redefine still GetEnumerator on the which does the same (and I first tried it ), but it was clarified that ItemsControl does not pull IEnumerable when is ICollection.

2

Re: Total row (footer) for standard WPF DataGrid

1. And how this piece behaves, when the user fulfills sorting ( on  columns)?
2. And how this piece will behave at grouping of the data?

3

Re: Total row (footer) for standard WPF DataGrid

1. As it is necessary works, just because of the user sorting it is all and it was necessary to stir up.
2. Did not try, I suppose, similarly. It after all works after all sortings and groupings.

4

Re: Total row (footer) for standard WPF DataGrid

And yes, 3: in my opinion, this last total line will be problematic to assign own style of display - it will be in general ItemsControl. It is necessary to enter for it any additional distinguisher, and to use ItemContainerStyleSelector.
And 4: This total line will leave downwards at  (since it will be in general ItemsControl). How it to make always visible?

5

Re: Total row (footer) for standard WPF DataGrid

3. Well I am simple in model added bool IsTotalRow and on it hung up the necessary handling in representations. And generally, same level of model of a line, instead of collection level. That is, dares as usual.
4. At me such task was not. I think that on the basis of regular DataGrida it is a problem of figs you will solve. If only to try to do two DataGrid and to synchronize width of their columns, but it another story altogether.

6

Re: Total row (footer) for standard WPF DataGrid

On idea, here there is such still a lack - there will be no events of change of a collection at change of property LastElement, well it can be added.

7

Re: Total row (footer) for standard WPF DataGrid

Clearly, thanks for idea, can, somewhere it is useful.

Shocker. Pro wrote:

I Think that on the basis of regular DataGrida it is a problem of figs you will solve. If only to try to do two DataGrid and to synchronize width of their columns, but it another story altogether.

Well, I and made in due time -  here it , and finished a file, since very much not  to contact   (very much it heavy), and it was required to make fixed footer with totals (which, certainly, would change the sizes at change of the sizes of columns, disappeared at concealment of columns, ).

8

Re: Total row (footer) for standard WPF DataGrid

All is correctly made. smile
As it is implemented NewItemPlaceholder inherently smile

9

Re: Total row (footer) for standard WPF DataGrid

Here and one more lack - will be a total line more low  if to resolve adding.))
And it can and not a lack, and and it is more logical. smile))