views:

38

answers:

1

Is there any way for me to do this?

+1  A: 

You can tell when the VerticalOffset changes by adding a handler to the ScrollViewer.ScrollChanged event to your TextBox. Something like this:

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

The TextBox uses a ScrollViewer internally, so it's ScrollChanged event will bubble up to the TextBox (where you can handle it). The event arguments include information about what changed, such as the VerticalChange (the amount that the control has scrolled vertically).

private void TextBox_ScrollChanged(object sender, ScrollChangedEventArgs e) {
    System.Diagnostics.Debug.WriteLine(string.Format("************ {0}", e.VerticalChange));
}
Tom Goff
Is there any way to add the handler in code? I tried doing this: this.ScrollViewer.ScrollChangedEvent += OnVerticalOffsetChanged; But I get an error.
Justin
You would need to call textBox.AddHandler(ScrollViewer.ScrollChanged, new ScrollChangedEventHandler(this.TextBox_ScrollChanged))
Tom Goff
Thank you Tom Goff!
Justin