【问题标题】:Getting the visible items inside Gridview(Windows store)获取 Gridview(Windows 商店)中的可见项目
【发布时间】:2014-03-18 11:35:42
【问题描述】:

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

请提出正确的方法来实现这一目标。一些代码片段会很有帮助。

提前致谢。

【问题讨论】:

  • 您只想获取对用户可见的项目?正常的实现真的很奇怪,这是不可能的。如果你真的需要这个,你需要看到增量实现。但是,在您的应用程序中多说些我们,我们可以找到我认为的解决方案。
  • 很遗憾,我们不是来为您工作的。最重要的是,您的要求非常苛刻,这可能是您投反对票的原因。在这个网站上,你需要证明你至少做了最基本的研究。 MSFT 提供了很多示例应用程序,它们实际上描述了这里的确切场景,并留给您一些次要的实现细节。如果您在此过程中走得更远并且对特定实例有特定问题,请随时返回并询问。祝您旅途愉快。
  • @Nate 没有冒犯意味着队友。如果我遇到要求,我很抱歉。
  • @Nate 没有冒犯意味着队友。如果我遇到要求很高的情况,我深表歉意。@MatDev8 谢谢。我会简要解释一下。我在数据模板中有一个 Gridview,我有一个绑定到视图模型的网格。该网格根据数据重复多次。我想如果我找出每个网格项目的坐标,我可以找到这些项目使用视口坐标可见。但是,如果我遍历网格的项目说 foreach(var item in _grdVw),我将 gt 视图模型实例而不是 GrdVw.Plz 中的项目,如果知道的话,建议更好的方法。
  • 完全不用担心,我只是想解释一下社区的反应。当您说“我将获取视图模型实例,而不是 GridView 中的项目”时,您的意思是您正在尝试获取UIElements(即GridViewItems)吗?如果是这样,您为什么需要这样做?

标签: c# gridview windows-store-apps windows-8.1


【解决方案1】:
         //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
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-18
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 2016-03-31
    • 2014-12-07
    相关资源
    最近更新 更多