nidarshani fernando
nidarshani fernando

Reputation: 533

WPF _ TextBlock Vertical ScrollBar issue

I have a stackpanel like in the following.

    <Stackpanel>
         <Grid>
             <Grid.RowDefinitions>
                 <RowDefinition/>
                 <RowDefinition/>
             </Grid.RowDefinitions>

         < TextBlock Text="SomeText"  Grid.Row="0"/>

         <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" >

             <TextBlock Text="Some Other Text"/>
       </ScrollViewer>
    </Grid>
    </StackPanel>

I want the second text block to have a vertical scroll bar. But it does not show the vertical scroll bar. Does anyone know what the issue is ?

Upvotes: 0

Views: 587

Answers (3)

Jayasri
Jayasri

Reputation: 235

This one working Try this .cs page add this line txt1.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;

<Grid x:Name="LayoutRoot">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
         </Grid.ColumnDefinitions>
    <ScrollViewer>
        <StackPanel x:Name="RightPanel"
                    Margin="5,0"
                    ScrollViewer.HorizontalScrollBarVisibility="Visible"
                    ScrollViewer.VerticalScrollBarVisibility="Visible">
            <TextBox TextWrapping="Wrap" Height="50" x:Name="txt1"  Text="Some Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other Text"/>
        </StackPanel>
    </ScrollViewer>
</Grid>

Upvotes: 2

bit
bit

Reputation: 4487

  1. Get rid of the stackpanel
  2. Add Heights to the RowDefinitions
  3. Set TextWrapping for the TextBlock

So your code should look like:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <TextBlock Text="SomeText"  Grid.Row="0"/>

    <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" >
        <TextBlock TextWrapping="Wrap" Text="Some Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other TextSome Other Text"/>
    </ScrollViewer>
</Grid>

Upvotes: 0

Anka
Anka

Reputation: 186

Try something like this (set ScrollViewer Width and Height and TextWrapping in TextBox):

<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Visible" 
              HorizontalScrollBarVisibility="Disabled" 
              Width="70" Height="50">
     <TextBlock Text="Some Other Text tststssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss" 
                TextWrapping="Wrap"/>
 </ScrollViewer>

Upvotes: 0

Related Questions