SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Syncronizing Scroll For Two TextView

Last post 06-16-2017 7:19 PM by MKrug. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-28-2017 9:04 PM

    • MKrug
    • Not Ranked
    • Joined on 04-13-2017
    • Kansas City
    • Posts 8

    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?

  • 04-29-2017 10:15 AM In reply to

    Re: Syncronizing Scroll For Two TextView

    As long as you have as much text-lines left and right, it should be possible.

    But why nog work with a grid, where left and right are textboxes, but each text (left) and comment (right) have their own grid-row.

     

  • 05-01-2017 9:02 PM In reply to

    • MKrug
    • Not Ranked
    • Joined on 04-13-2017
    • Kansas City
    • Posts 8

    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.

    Any ideas? Anything?

    Currently I have the structure as follows:

    <DocumentContent>

    -----<Grid>

    ----------<DockPanel>

    ---------------<Grid>

    --------------------<TextEditor Grid.Column="0">

    --------------------</TextEditor>

    --------------------<GridSplitter>

    --------------------<TextEditor Grid.Column="1">

    --------------------</TextEditor>

    ---------------</Grid>

    ----------</DockPanel>

    -----</Grid>

    </DocumentContent>

  • 05-03-2017 6:07 PM In reply to

    • MKrug
    • Not Ranked
    • Joined on 04-13-2017
    • Kansas City
    • Posts 8

    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.

    Structure:

    <DocumentContent> 
         <Grid>
            <DockPanel>
                <ScrollViewer >
                     <Grid>
                     <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                     </Grid.ColumnDefinitions>
                           <TextEditor Grid.Column="0" ScrollViewer.VerticalScrollBarVisibility="Hidden">
                           </TextEditor>
                           <GridSplitter  MinWidth="5" MaxWidth="10" ShowsPreview="True" DragIncrement="5" />
                           <TextEditor Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Hidden">
                           </TextEditor>
                     </Grid>
                </ScrollViewer>
            </DockPanel>
        </Grid>
    </DocumentContent>

  • 06-16-2017 7:19 PM In reply to

    • MKrug
    • Not Ranked
    • Joined on 04-13-2017
    • Kansas City
    • Posts 8

    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.

Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.