我试图将垂直滚动条保留在底部(最新条目),但目前,滚动条只是停留在同一个位置,因此当内容被添加到字符串中时,滚动条会移动到顶部。
我知道我可以使用ServerScroll.ScrollToEnd()代码隐藏中的属性将栏移动到末尾。但是有没有办法用xaml自动做到这一点?(这样我就不必每次添加到字符串时都调用此属性)。
XAML
<ScrollViewer Name="ServerScroll"
VerticalScrollBarVisibility="Auto">
<TextBlock Name="serverConsole"
Margin="5"
Background="White"
TextWrapping="Wrap"/>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
代码隐藏
private void example_Click(object sender, RoutedEventArgs e)
{
ServerConsole += "asdf\r\n"; // binded to TextBlock
ServerScroll.ScrollToEnd();
}
Run Code Online (Sandbox Code Playgroud)