获取Gridview(Windows store)中的可见项

本文关键字:Gridview Windows store 获取 | 更新日期: 2023-09-27 17:50:49

我正在开发一个Windows商店应用程序,对c#和Windows框架有点陌生。我有一个gridview并且数据绑定正在使用gridview完成。ItemTemplate和DataTemplate。Gridview在任何时间点都可能有多个项目。而且我必须只获取当前对用户可见的项目。

请建议正确的方法来实现这一点。一些代码片段会很有帮助。

获取Gridview(Windows store)中的可见项

         //I think i found the answer
         //GridList is the list of items inside the GridView    
     //grv is the gridView instance
     //sv is the scrollview
        Rect bounds = Window.Current.Bounds;                        
        double height = bounds.Height;
        double width = bounds.Width;
        var ttf = sv.TransformToVisual(Window.Current.Content);
        Windows.Foundation.Point screenCoordsSv = ttf.TransformPoint(new Windows.Foundation.Point(0, 0));
        foreach (Grid grv in GridList)
        {                
            double gridWidth = grv.Width;

            var ttv = grv.TransformToVisual(Window.Current.Content);
            Windows.Foundation.Point screenCoords = ttv.TransformPoint(new Windows.Foundation.Point(0, 0));
            if ((screenCoords.X >= -(gridWidth + 10)) && (screenCoords.X < width))
            {                    
               //item falls inside the visible area
            }
        }