2010-04-13 70 views
3

事件scrolltoVerticalOffset或scrolltoHorizo​​ntalOffset不会更改scrollviewer的值。 请告诉我在哪个事件中Horizo​​ntalOffset和VerticalOffset的值发生了变化? 我试过LayoutUpdated()方法,但它进入了一个无限循环。wpf scrollviewer scrolltoverticaloffset

预先感谢

回答

1

通常不更新的HorizontalOffsetVerticalOffset值被除ScrollContentPresenter(或其它IScrollInfo)之后的LayoutUpdated事件期间已经更新了其价值和称为InvalidateScrollInfo()。唯一的例外是在延期滚动期间更新了每个DependencyProperty的DependencyProperty(但令人惊讶的是相应的CLR属性未更新),但这可能不适用于您的情况。

没有ScrollToHorizontalOffsetScrollToVerticalOffset events in WPF, but there is both a ScrollViewer method and a RoutedCommand of these names. Both the command version and the method version remember your request and execute it at the next LayoutUpdated`事件,所以如果您要做的只是确保滚动发生,只需发送命令或调用方法即可。

如果您想验证HorizontalOffsetVerticalOffset根据需要,你可以简单地赶上ScrollChangedEvent,其值后,大火已被更新,这样确实已更新:

scrollViewer.ScrollChanged += (obj, e) => 
{ 
    // Get offset information from 'e' or from scrollViewer 
} 

我不明白你的意思是“我尝试过LayoutUpdated()方法,但它进入了一个无限循环”,因为你没有解释“LayoutUpdated()方法”是什么,但是上面的信息应该使事件的顺序变得清晰并且帮助你你的解决方案。无论如何,您需要做出决定所需的所有信息都可以从ScrollChanged事件中获得。

1

我遇到了同样的问题,感谢张贴解决方案。 当您使用ScrollChanged()而不是LayoutUpdated()修复了问题时,LayoutUpdated()方法在无限循环中由框架调用。