Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The straightforward solution seemed to be <code>FrameworkContentElement.BringIntoView()</code> but after putting it in the code below it initially had no effect. As it turns out this is one of these timing issues (I've seen similar problems in WinForms) that can be solved by processing the outstanding Windows Messages. WPF has no direct equivalent of <code>DoEvents()</code> but there exists a well known substitute.</p> <p>I placed this in a ButtonClick, changes marked with <code>//**</code>:</p> <pre><code> Paragraph paragraph = new Paragraph(); Inline selected = null; //** richTextBox1.SelectAll(); richTextBox1.Selection.Text = ""; string text = System.IO.File.ReadAllText(@"..\..\MainWindow.xaml.cs"); int iZeile = 0; string[] split = text.Split(new string[] { "\r\n" }, StringSplitOptions.None); foreach (string s in split) { if (iZeile != 27) { paragraph.Inlines.Add(s + "\r\n"); // adds line added without marking } else { Run run = new Run(split[27]); // adds line with marking run.Background = Brushes.Yellow; paragraph.Inlines.Add(run); paragraph.Inlines.Add("\r\n"); selected = run; // ** remember this element } iZeile++; } FlowDocument document = new FlowDocument(paragraph); richTextBox1.Document = new FlowDocument(); richTextBox1.Document = document; Keyboard.Focus(richTextBox1); DoEvents(); // ** this is required, probably a bug selected.BringIntoView(); // ** </code></pre> <p>And the helper method, from <a href="https://stackoverflow.com/a/4502200/60761">here</a>:</p> <pre><code> public static void DoEvents() { Application.Current.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { })); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload