Syncronizing Scroll For Two TextView

I am trying to implement a solution that contains two TextView side-by-side. The left pane contains a file's content and the left pane is comments and automatically generated text based on the content of the left pane. I am using a GridSplitter between the two panes. This creates two vertical and horizontal scrollbars for the two TextView. Since the content on the right is a response / generated by the content on the left; I need for both views to be in "sync" with each other. Meaning when I scroll down on the left pane, I need the right pane to also scroll down. Anyone ever done this? Does anyone have any idea how to do this?

Re: Syncronizing Scroll For Two TextView

I do actually use a Grid, with two TextEditors inbedded in the Grid; with a GridSplitter between. The TextEditor windows are used so that "decoration" is easier. However, previously it was 1 TextEditor containing a file's content, split into two by drawing a rectangle (using Rect) background renderer, with visual text overlayed onto the rectangle, then the left portion only occupying the space that does not contain the rectangle background; through measures such as Offset = TextArea - Rect.

Problem is that they now want to simultaneously scroll, print, & search, while being able to adjust the right pane on the fly / runtime. Printing a background image BESIDE text is challenging but obtainable (although I do not know why you would want to go through all that trouble, when you can just change it to a TextView). But, you can not "search" on a background image. Not to mention, adjusting the right pane is easier with a GridSpitter than a drawn visual that I would have to add handles to somehow.

So, I needed to convert the right panel to a text view instead of a background with text, put a GridSplitter between, then figure out how to simultaneously scroll both windows, print both windows, and have the ability to search both windows. See my dilema now?

I posted each challenge seperately on the board (Scroll Two Panes, Print Two Panes, Search Two Panes), but really it is one huge problem / initiative.

Re: Syncronizing Scroll For Two TextView

I have managed to get the scrolling of two Textviews to be syncronized. And, the solution was so simple I wanted to kick myself for not trying it before. I simply wrapped everything in a ScrollViewer. Hid the vertical scrollbars using ScrollViewer.VerticalScrollBarVisibility, so that only the ScrollViewer's Scrollbar could scroll vertically. I left the HorizontalScrollBarVisibility alone so that if one of the two views was wider than the pane I did not have to deal with wrapping, since I put a GridSplitter in-between the two panes. That way the user could adjust the width of the views without affecting the text. This appears to be working well actually.

Re: Syncronizing Scroll For Two TextView

Update: Wrapping TextEditor(s) in ScrollView is incredibly slow if the file is large. It sometimes takes 30 - 40 seconds to load / draw the document, and as long as 40 - 50 seconds for a ReDraw. In my example if I move the GridSplitter it forces a ReDraw and takes forever. In attempting to display a message to let the user know that it is re-drawing the window and to be patient, I found that there really is no great event handler to place this message as due to the lag time I had to enable PreviewDrag, and the Preview event fires the redraw itself automatically by default therefore it redraws before displaying the message (defeating the purpose of the message).

Had to simply "bind" the two views scrollbars together through the ScrollOffsetChanged for both the views. Problem is, this requires both documents / content to be the same length, else it stops at the last line of the shorter of the two views. Work around until I figure this out entirely. Not a real solution to the problem, but works for now until I can analyze the problem further.