Scroll element of the DataGrid class WPF C #

2

I have a function that creates a grid, and I needed to know the value of the scroll of this grid, so I can trigger an event when it reaches the bottom of the page. But I do not know how to get those values, the function is down here:

using System.Windows.Controls;

     public override FrameworkElement criar()
        {
          if (formulario == null)
            return null;

          DataGrid    grid = new DataGrid();
          ContextMenu menu = new ContextMenu();


          definirStyle(grid, "tema.estiloGradeDados");
          definirBinding(grid, DataGrid.ItemsSourceProperty, "dados", true);

          grid.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
          grid.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;

          grid.GroupStyle.Add(new GroupStyle() {ContainerStyleSelector = new SeletorEstiloItemGrupo() });
          grid.ContextMenu = menu;

          grid.Height = 800;

          foreach (DskCampo campo in dskFormulario.campos)
          {
            criarItemMenu(menu, campo);
            criarColuna  (grid, campo);
          }

          return grid;
        }

The scroll of the DataGrid descends from "ScrollViewer" not? how do I manipulate it?

    
asked by anonymous 05.07.2018 / 21:25

2 answers

0

The DataGrid has a property named ScrollViewer, in it you can add the scroll event (ScrollChanged) and have several properties: ContentVerticalOffset, and several other properties related to vertical scrolling and size.

Source: ScrollViewer.ContentVerticalOffsetProperty Field

    
05.07.2018 / 23:23
0

At your ScrollChanged event, you can use the code below:

int AlturaTotal = 0;
foreach (DataGridViewRow row in grid.Rows){
    AlturaTotal += row.Height;
}

if (AlturaTotal - grid.Height < grid.VerticalScrollingOffset)
{
    //quando entrar aqui é por que chegou na ultima linha
}
    
06.07.2018 / 16:19