[英]How to get a WPF TextBlock to scroll where the Text property is set asynchronously?
I have a TextBlock
, wrapped in a ScrollViewer
, and the Text
property of the TextBlock
is set with the result of a Task. 我有一个
TextBlock
,包装在ScrollViewer
, TextBlock
的Text
属性设置为Task的结果。 The scrollbars of the TextBlock
do not adjust to the size of the text returned by the task. TextBlock
的滚动条不会调整为任务返回的文本大小。
Any ideas? 有任何想法吗?
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto"
Height="177"
Width="500"
HorizontalScrollBarVisibility="Disabled">
<TextBlock Height="177"
Text="Extracted Xml"
Width="504"
HorizontalAlignment="Stretch"
TextWrapping="Wrap" />
</ScrollViewer>
</Grid>
ScrollViewer
calculates it's scrollbars based on dimensions of child controls. ScrollViewer
根据子控件的尺寸计算它的滚动条。
Thus, remove Height
property from your TextBlock
and ScrollBars should work as expected 因此,从
TextBlock
删除Height
属性,ScrollBars应该按预期工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.