none
如何自己实现GridViewItem的Swipe效果? RRS feed

  • 问题

  • 由于某些特殊原因吧,

    不能使用GridView控件,

    而是在ScrollViewer中,放一个大Panel,Panel中摆放若干个GridViewItem,

    这样的话,Swipe效果就需要自己实现。

    可是在ScrollViewer中进行触控操作,

    无法收到PointerMove事件,

    因此,没有时机触发Swipe效果。

    如果用

    ManipulationMode.All,接收

    ManipulationDelta事件的话,

    则触控不能操作ScrollViewer滚动。

    想请教一下这个问题有何解决办法?

    2013年8月30日 2:52

答案

  • Hi 马里,

    我找过同事问了下,首先ScrollView会吃掉所有的手势动作,所以你的任何Manipulation都没有什么用,同时他有一个博客文章应该可以帮到你: http://blogs.msdn.com/b/wsdevsol/archive/2013/02/16/where-did-all-my-gestures-go.aspx

    Unfortunately there is no good solution if the app needs both scrolling and gestures (for example, to detect CrossSlides against the scrolling). In this case the only option to get the Pointer messages everywhere is to disable Direct Manipulation everywhere, but that disables scrolling as well. To get that back the app will need to detect the scrolling gestures itself and then navigate the ScrollViewer to the new location with ScrollToHorizontalOffset or ScrollToVerticalOffset or by updating the SelectedIndex. This is tricky and will be noticeably slower than letting the ScrollViewer do its thing. It should be avoided if at all possible.

    多谢对Windows Store App Dev论坛的支持。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • 已标记为答案 马里 2013年9月6日 1:57
    2013年9月5日 1:23
    版主

全部回复

  • 简单的说,

    就是如何对ScrollViewer中的Item实现Swipe选中的效果,

    项目卡在这个问题上,

    急需解决,

    恳请高手现身,帮忙解答,感激不尽~~

    2013年9月2日 2:17
  • Hi 马里,

    我能问下不能使用GridView的原因么?如果你可以基于GridView写一个类,把你不需要的东西去掉也应该是个不错的办法。

    另外如果想实现ScrollViewer中Item滑动选择的效果,有点难度,一般Swipe事件都是通过pointer来处理的。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月2日 7:56
    版主
  • 开发的项目是基于Win8的,之前是使用GridView控件来的,

    大量图片,按照时间月份分组显示。

    不过每个GridViewItem大小不一,

    已有的VariableSizedWrapGrid满足布局效果,

    但不能满足UI虚拟化的性能要求,

    满足UI虚拟化的Panel又不能满足布局要求,

    因此放弃使用GridView控件。

    之前调查GridView控件发现,

    当IsSwipeEnabled = true时,

    在Swipe选择过程中,可以产生PointerMove事件,

    而IsSwipeEnabled = false时,做同样手势,没有Swipe效果的同时,也不再产生PointerMover事件,

    不知GridView控件,在IsSwipeEnabled = true时做了什么,才会有这样的效果?

    2013年9月2日 8:16
  • 参考了一下如下链接的内容:

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/b4ac8501-ddf4-4ff6-9758-e7d7768d1838/why-short-swipe-is-not-working-for-gridview-when-scrollviewer-is-removed-from-its-style-template

    自己也试了一下,发现将ScrollViewer从GridView的ControlTemplate中移除,或者换成别的,

    尽管将IsSwipeEnabled = true,仍然无法进行Swipe操作,

    说明IsSwipeEnabled = true时,GridView对ScrollViewer的某些行为做了改变,

    只是不知道做了哪些改变,因此该问题还未解决。

    PS:很感谢James之前的回复~

    2013年9月4日 3:08
  • Hi 马里,

    目前来说我也没有办法去帮你回答这个问题,我对内部的机制不能算非常清楚,也说不明白,不过我尽量帮你去问一下专家看看他们有没有什么好的建议,多谢对论坛的支持。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    2013年9月4日 6:13
    版主
  • 好的,James, 感谢你的帮助~

    2013年9月4日 6:34
  • Hi 马里,

    我找过同事问了下,首先ScrollView会吃掉所有的手势动作,所以你的任何Manipulation都没有什么用,同时他有一个博客文章应该可以帮到你: http://blogs.msdn.com/b/wsdevsol/archive/2013/02/16/where-did-all-my-gestures-go.aspx

    Unfortunately there is no good solution if the app needs both scrolling and gestures (for example, to detect CrossSlides against the scrolling). In this case the only option to get the Pointer messages everywhere is to disable Direct Manipulation everywhere, but that disables scrolling as well. To get that back the app will need to detect the scrolling gestures itself and then navigate the ScrollViewer to the new location with ScrollToHorizontalOffset or ScrollToVerticalOffset or by updating the SelectedIndex. This is tricky and will be noticeably slower than letting the ScrollViewer do its thing. It should be avoided if at all possible.

    多谢对Windows Store App Dev论坛的支持。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • 已标记为答案 马里 2013年9月6日 1:57
    2013年9月5日 1:23
    版主