I need the following scrolling behavior, but this only works, if the window is not minimized. Is there a solution that works, even if the window is minimized?
c#
private void richTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (richTextBox.VerticalOffset + richTextBox.ViewportHeight >= richTextBox.ExtentHeight)
{
richTextBox.ScrollToEnd();
}
}
xaml
<Grid>
<RichTextBox Name="richTextBox" IsReadOnly="True" VerticalScrollBarVisibility="Auto" TextChanged="richTextBox_TextChanged">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</RichTextBox.Resources>
</RichTextBox>
</Grid>
Call the ScrollToEnd
also in the StateChanged
event of the window. So it is done when the window returns from minimized state.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.