How to get a WPF TextBlock to scroll where the Text property is set asynchronously?
24,110
ScrollViewer
calculates it's scrollbars based on dimensions of child controls.
Thus, remove Height
property from your TextBlock
and ScrollBars should work as expected
Author by
MalcomTucker
Updated on January 28, 2020Comments
-
MalcomTucker over 4 years
I have a
TextBlock
, wrapped in aScrollViewer
, and theText
property of theTextBlock
is set with the result of a Task. The scrollbars of theTextBlock
do not adjust to the size of the text returned by the task.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>
-
amit jha about 8 years
MaxHeight
also should be removed if present.