2010-04-13 59 views

回答

6

通过向ScrollBox的ScrollViewer.ScrollChanged事件添加处理程序,您可以知道VerticalOffset何时更改。事情是这样的:

<TextBox AcceptsReturn="True" ScrollViewer.ScrollChanged="TextBox_ScrollChanged" /> 

文本框使用的ScrollViewer内,所以它的ScrollChanged事件会冒泡到TextBox(在那里你可以处理它)。事件参数包含有关更改内容的信息,例如VerticalChange(控件垂直滚动的数量)。

private void TextBox_ScrollChanged(object sender, ScrollChangedEventArgs e) { 
    System.Diagnostics.Debug.WriteLine(string.Format("************ {0}", e.VerticalChange)); 
} 
+0

有什么办法可以在代码中添加处理程序吗?我试过这样做: this.ScrollViewer.ScrollChangedEvent + = OnVerticalOffsetChanged; 但我得到一个错误。 – Justin 2010-04-14 23:06:35

+2

您需要调用textBox.AddHandler(ScrollViewer.ScrollChanged,new ScrollChangedEventHandler(this.TextBox_ScrollChanged)) – CodeNaked 2010-04-15 13:40:30

+0

谢谢Tom Goff! – Justin 2010-04-15 16:52:38

相关问题