【问题标题】:Setting ScrollViewer.ManipulationMode to System doesn't seem to work将 ScrollViewer.ManipulationMode 设置为 System 似乎不起作用
【发布时间】:2014-11-26 15:52:05
【问题描述】:

我有一个使用 ListBox 实现的分层树。我通过按住一个项目并拖动它来实现项目重新排序方法。

为此,我拦截了项目的 HoldManipulationDeltaManipulationCompleted 事件。因为 Listbox 的 ScrollViewer 默认在 ManipulationMode = ManipulationMode.System 中,所以我需要将其设置为 ManipulationMode.Control 以暂时禁用它以便能够拖动我的项目。

如果我不这样做,scrollviewer 会拦截我的 ManipulationDelta 事件,因此当用户尝试拖动项目时,他会滚动滚动查看器并且我的项目保持在固定位置。

通常,在用户放下项目后,我想将其设置回 ManipulationMode.System(如果我不这样做,树结构滚动仍然滞后,因为项目的模板有点重/复杂)。

private void ElementHold(object sender, GestureEventArgs e) {
    ....
    _scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
    _scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;   
    // works ok     
    _scrollViewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.Control);
}

private void ElementManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
    _scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
    _scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

    // ▼ this doesn't seem to work. 
    // ▼ In the debugger ManipulationMode has correct value but scrolling 
    // ▼ still lags which means that scrollviewer stays in Control mode.
    _scrollViewer.SetValue(ScrollViewer.ManipulationModeProperty, ManipulationMode.System);
}

我读到在调用 ApplyTemplate() 后我无法切换 ManipulationMode,但我还读到如果通过依赖属性而不是标准属性进行设置,它应该是可能的。

我在这里做错了什么?是否无法返回系统模式?如果我转到其他页面并返回此页面,scrollViewer 仍然会滞后。只有应用重启有效。

【问题讨论】:

    标签: windows-phone-8 windows-phone scrollviewer


    【解决方案1】:

    只需将 UseOptimizedManipulationRouting="False" 设置为拖动项目控件以防止 Routing 事件到滚动查看器

    【讨论】:

      猜你喜欢
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 2019-06-19
      • 2015-12-15
      • 1970-01-01
      • 2016-09-14
      相关资源
      最近更新 更多