wpf radgridview如何获取GridViewRow的垂直偏移量?

时间:2017-05-02 10:23:03

标签: wpf telerik radgridview

我有目标GridViewRow的行索引,以及RadGridView中GridViewScrollViewer的ScrollChanged处理程序回调。我希望在视口中获得目标行的垂直偏移,同时滚动,如果该行从顶部离开视口,则返回0;如果从底部离开,则返回RadGridView的ActualHeight;否则,获取与目标行和视口的Top offest相同的值。

这是获取垂直偏移的函数,滚动条移动后它将是不正确的:



    //const int indicator_size = 3;
    //RadGridView grid;
    Func rowIndicatorOffset = (rowIndex) =>
    {
        double offset = (rowIndex + 1.5) * this.grid.RowHeight;
        if (offset > this.grid.ActualHeight)
        {
            return this.grid.ActualHeight - indicator_size;
        }
        return offset;
    };

effects on UI

当更改垂直滚动条偏移时,我希望该指标(上图中的红色)与目标行保持相同的Y位置:



    //System.Windows.Controls.ScrollChangedEventArgs offsetValues (from ScrollChanged event)
    double fixRatio = (this.grid.ActualHeight - this.offsetValues.VerticalOffset) / this.grid.ActualHeight;
    double offset = (rowIndex + 1.5) * this.grid.RowHeight * fixRatio;

上面的代码显然效果不如预期,那么答案是什么?

expected effect

1 个答案:

答案 0 :(得分:0)

我对Viewport说错了,下图可能会弄明白。

diagram



    //const int indicator_size = 3;
    //RadGridView grid;
    Func<int, double> rowIndicatorOffset = (rowIndex) =>
    {                   
        double targetOffset = (rowIndex + 1.5) * this.grid.RowHeight;
        double viewportOffset = this.offsetValues.VerticalOffset;
        double offset = targetOffset - viewportOffset;
        if (offset > this.grid.ActualHeight)
        {
            return this.grid.ActualHeight - indicator_size;
        }
        else if (offset < 0)
        {
            return 0;
        }
        else
        {
            return offset;
        }
     };