如何在WPF中以编程方式滚动网格?

时间:2014-01-21 06:15:43

标签: c# wpf wpfdatagrid

我正在c#应用中的WPF代码生成网格。我的grid是使用代码动态生成的,它包含很多行。我想在网格中scroll the grid to some specific element,因此用户可以将特定元素视为网格中的第一条记录。能否帮助我们如何在WPF中以编程方式滚动网格?

1 个答案:

答案 0 :(得分:0)

DataGrid.ScrollIntoView会为你工作吗?第一个参数(item)是您要显示的元素。

    //
    // Summary:
    //     Scrolls the System.Windows.Controls.DataGrid vertically and horizontally
    //     to display a cell for the specified data item and column.
    //
    // Parameters:
    //   item:
    //     The data item to bring into view.
    //
    //   column:
    //     The column to bring into view.
    public void ScrollIntoView(object item, DataGridColumn column);