ScrollViewer和处理子元素上的操作事件

Col*_*inE 5 windows-8 windows-runtime winrt-xaml windows-store-apps

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

这是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>
Run Code Online (Sandbox Code Playgroud)

我知道WinRT ScrollViewer使用了一个特殊ManipulationModeSystem性能原因,但我想有一个垂直滚动列表,包含响应水平操作/手势的元素.任何人都可以想到一个创造性的解决方案,使这成为可能吗?

Mis*_*tyK 10

可能很长时间但没有找到任何好的解决方案.我很容易实现了我想要的东西.

public MovableGrid()
        {
            ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.System;
            AddHandler(ManipulationDeltaEvent, new ManipulationDeltaEventHandler(UIElement_OnManipulationDelta), true);
            AddHandler(ManipulationCompletedEvent, new ManipulationCompletedEventHandler(UIElement_OnManipulationCompleted), true);
        }
Run Code Online (Sandbox Code Playgroud)

我希望我的MovableGrid在X轴上移动,我有MovableGrids列表,我想用scrollviewer滚动它.这足以做到这一点.


Fil*_*kun 8

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

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

编辑2*

另外,对于Windows 8.1,您可以ManipulationModes.System使用与其他模式结合使用来处理内部操作ScrollViewer.然后,CancelDirectManipulations()一旦您希望其父级ScrollViewers停止处理平移和缩放操作,您就可以调用操纵元素.