我正在开发一个Windows应用商店应用程序,它是C#和Windows框架的新手。我有一个gridview,数据绑定正在使用GridView.ItemTemplate和DataTemplate完成。 Gridview可能在任何时间点都有多个项目。而且我必须只获取用户当前可见的项目。
请建议正确的方法来实现这一目标。一些CODE SNIPPETS非常有用。
提前致谢。
答案 0 :(得分:0)
//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
}
}