Scroll text in a textblock from code behind
i need to scroll the textblock text. F开发者_高级运维or example, the textblock contains 700 words. These words are populated to the textblock from code behind as it could be a different 700 words depending on some "stuff". There is a textbox on this form as well. The user types the words in the textblock into the textbox. As they type i keep track of which word from the textblock they are on. However, not all the words in the textblock will fit in the textblock viewing area, so i need to scroll the textblock from code behind. How do i go about doing this.
I"m using silverlight 3.
Thanks shannon
sorry.. i didn't realize i didn't ask the question on it's own thread.. I'll post again..
First you'll want to wrap your TextBlock in a ScrollViewer control. At that point, you can set the vertical and horizontal offsets of the ScrollViewer in the code behind like this. Note this assumes a ScrollViewer control named ScrollViewer1.
Private Sub ScrollViewer1_MouseWheel(ByVal sender As Object, By Val e as System.Windows.Input.MouseWheelEventArgs)
Me.ScrollViewer1.VerticalOffset = Me.ScrollViewer1.VerticalOffset + e.Delta
End Sub
精彩评论