alerya
alerya

Reputation: 3175

TextBlock Wrap and scrollView

The code below is working nice but the vertical ScrollBar is disabled even if large text inside of TextBlock. How can I enable it?

 <UserControl.DataContext>
        <viewModels:CommentsViewModel/>
    </UserControl.DataContext>
    <Grid>
        <DockPanel >
            <TreeView DockPanel.Dock="Top"/>
            <Expander Header="Yo" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
                <ScrollViewer HorizontalScrollBarVisibility="Disabled">
                    <TextBlock TextWrapping="Wrap"  MaxHeight="250" 
                         Text="{Binding Article.Article.Content}"/>
                </ScrollViewer>
            </Expander>
        </DockPanel>
    </Grid>

Upvotes: 0

Views: 1058

Answers (2)

alerya
alerya

Reputation: 3175

I found.

MaxHeight="250" 

tag should be not in the TextBlock, but should be in the Grid to limit height. Then it will be working perfectly.

<UserControl.DataContext>
    <viewModels:CommentsViewModel/>
</UserControl.DataContext>
<Grid>
    <DockPanel >
        <TreeView DockPanel.Dock="Top"/>
        <Expander Header="Yo" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
            <Grid MaxHeight="250"> 
            <ScrollViewer HorizontalScrollBarVisibility="Disabled">
                <TextBlock TextWrapping="Wrap"   
                     Text="{Binding Article.Article.Content}"/>
            </ScrollViewer>
            </Grid>
        </Expander>
    </DockPanel>
</Grid>

Upvotes: 1

TMan
TMan

Reputation: 4122

If your just displaying text, to be certain it'll work use a TextBox:

        <Expander Header="Yo" DockPanel.Dock="Bottom" VerticalAlignment="Bottom">
            <Grid IsReadOnly="True">
                <TextBox TextWrapping="Wrap"  MaxHeight="250" 
                     Text="{Binding Article.Article.Content}"/>
            </Grid>
        </Expander>

Upvotes: 0

Related Questions