将ScrollViewer.ManipulationMode设置为System似乎不起作用

时间:2014-04-11 09:46:09

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

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

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

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

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

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,但我也读到应该可以通过依赖属性设置而不是标准属性来实现。< / p>

我在这里做错了什么?是否无法返回系统模式?如果我转到其他页面并返回到此页面,则scrollViewer仍然会滞后。只有app重启才能正常工作。

1 个答案:

答案 0 :(得分:2)

只需将UseOptimizedManipulationRouting =“False”设置为拖动项目控件以防止路由事件转到滚动查看器