事件scrolltoVerticalOffset或scrolltoHorizontalOffset不會更改scrollviewer的值。 請告訴我在哪個事件中HorizontalOffset和VerticalOffset的值發生了變化? 我試過LayoutUpdated()方法,但它進入了一個無限循環。wpf scrollviewer scrolltoverticaloffset
預先感謝
事件scrolltoVerticalOffset或scrolltoHorizontalOffset不會更改scrollviewer的值。 請告訴我在哪個事件中HorizontalOffset和VerticalOffset的值發生了變化? 我試過LayoutUpdated()方法,但它進入了一個無限循環。wpf scrollviewer scrolltoverticaloffset
預先感謝
通常不更新的HorizontalOffset
和VerticalOffset
值被除ScrollContentPresenter
(或其它IScrollInfo
)之後的LayoutUpdated
事件期間已經更新了其價值和稱爲InvalidateScrollInfo()。唯一的例外是在延期滾動期間更新了每個DependencyProperty的DependencyProperty(但令人驚訝的是相應的CLR屬性未更新),但這可能不適用於您的情況。
沒有ScrollToHorizontalOffset
或ScrollToVerticalOffset 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`事件,所以如果您要做的只是確保滾動發生,只需發送命令或調用方法即可。
如果您想驗證HorizontalOffset
或VerticalOffset
根據需要,你可以簡單地趕上ScrollChangedEvent
,其值後,大火已被更新,這樣確實已更新:
scrollViewer.ScrollChanged += (obj, e) =>
{
// Get offset information from 'e' or from scrollViewer
}
我不明白你的意思是「我嘗試過LayoutUpdated()方法,但它進入了一個無限循環」,因爲你沒有解釋「LayoutUpdated()方法」是什麼,但是上面的信息應該使事件的順序變得清晰並且幫助你你的解決方案。無論如何,您需要做出決定所需的所有信息都可以從ScrollChanged
事件中獲得。
我遇到了同樣的問題,感謝張貼解決方案。 當您使用ScrollChanged()而不是LayoutUpdated()修復了問題時,LayoutUpdated()方法在無限循環中由框架調用。