Unable to go to line using FirstVisiblePosition

SyntaxEditor for WPF Forum

Posted 8 years ago by Kasper
Version: 11.1.0545
Avatar
Hi guys,

From another thread on this forum, I was made to believe that I could jump to a specific line using the FirstVisiblePosition. In this specific case, I need to make a certain line the first/top visible line in the control, so the property does sound like exactly what I'm looking for :). However, it doesn't seem to be working like it should, so I created a small demo to re-produce the problem. Here is the gist of it - everything else is just a standard WPF app with a SyntaxEditor control on the Window:
public MainWindow()
{
    InitializeComponent();
    syntaxEditor1.IsLineNumberMarginVisible = true;
    StringBuilder sb = new StringBuilder();
    for(int i = 1; i < 100; i++)
        sb.Append("Line "  +i + Environment.NewLine);
    syntaxEditor1.Document.SetText(sb.ToString());
    syntaxEditor1.ActiveView.FirstVisiblePosition = new ActiproSoftware.Text.TextPosition(50, 0);
}
When I run the code, the control seems to just scroll a single line down, so that the second line is in top. Line 50 is nowhere near. Am I missing something or is there a bug? :)

[Modified at 09/06/2011 04:41 AM]

Comments (2)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Kasper,

It looks like at that time (perhaps since it's still in the constructor), the editor hasn't completely loaded and laid out lines yet. You can work around it by doing this:
this.Dispatcher.BeginInvoke(DispatcherPriority.Render, (DispatcherOperationCallback)delegate(object arg) {
    editor.ActiveView.FirstVisiblePosition = new ActiproSoftware.Text.TextPosition(50, 0);
    return null;
}, this);
Or perhaps doing the FirstVisiblePosition setting in a Window.Loaded event handler would work too, but I didn't try that.


Actipro Software Support

Posted 8 years ago by Kasper
Avatar
Actually, I would definitely expect everything to be loaded and rendered when I actually use this code (it's not exactly as shown in the demo), but nevertheless, it works. Thank you :)
The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.