windows-8 – ScrollViewer和处理子元素上的操作事件

我使用C#/ XAML创建了一个Windows 8商店应用程序.我的界面包括一个可滚动的列表,使用ScrollViewer进行渲染.我希望能够处理列表中元素的操作事件,但是,将列表元素上的ManipulationMode设置为None以外的任何内容都会导致我的列表不再滚动.

这是UI的简化版本:

<ScrollViewer>
  <Border/> <!-- these contain child content -->
  <Border/>
  <Border/>
  <!-- Set ManipulationMode on an element in order to receive manipulation events -->
  <!-- This causes the scroll viewer to stop working! -->
  <Border ManipulationMode="All"
          ManipulationDelta="..."/>
  <Border/>
  <Border/>
</ScrollViewer>

据我所知,WinRT ScrollViewer出于性能原因使用了一个特殊的ManipulationMode系统,但是我希望有一个垂直滚动列表,其中包含响应水平操作/手势的元素.任何人都可以想到一个可以实现这一目标的创造性解决方案吗?

我所做的是在ScrollViewer顶部放置一个透明矩形并处理那里的操作.当我发现操作应滚动ScrollViewer时 – 我使用ScrollToHorizo​​ntal / VerticalOffset()方法滚动ScrollViewer.在ManipulationStarted上我也使用VisualTreeHelper.FindElementsInHostCoordinates检查我可以操作哪个项目然后我可以根据各种条件决定是否操作该项目.这是相当多的自定义代码.当用户尝试拖动远离最小/最大偏移量以模仿ScrollViewer认行为,处理鼠标滚轮等时,您还需要更新ScrollViewer中ScrollContentPresenter的RenderTransform.当然,您无法处理任何事情.不幸的是,我找不到更好的方法,如果有人找到,我感兴趣.

编辑*我在尝试回答another similar question时想到的另一个解决方案是使用另一个ScrollViewer作为子项并使用其ViewChanged事件而不是操作事件.

编辑2 *

另外,对于Windows 8.1,您可以获得ManipulationModes.System,它与其他模式结合使用,可以让您处理ScrollViewer内部的操作.然后,一旦您希望其父ScrollViewers停止处理pan& zoom操作,您就可以在受控元素上调用CancelDirectManipulations().

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...