简体   繁体   English

如何获取WPF TextBlock以滚动Text属性异步设置的位置?

[英]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 ,包装在ScrollViewerTextBlockText属性设置为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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM