N.D
N.D

Reputation: 1049

ScrollViewer wpf - doesn't work

I have a wpf application. In the window i have a TextBlock which contains a lot of numbers , each number in it's row. I want the scrollViewer to appear when needed. It doesn't work... here is the code

<ScrollViewer CanContentScroll="True" Margin="5,25,5,0" Grid.Row="2" HorizontalScrollBarVisibility="Auto" >
                 <TextBlock MaxHeight="500" Height="Auto" Width="Auto" VerticalAlignment="Top" Name="TextBlock_Results"/>
        </ScrollViewer>

Upvotes: 2

Views: 4759

Answers (1)

Mekboy
Mekboy

Reputation: 26

The text block in the scroll viewer is not capable of scrolling by default. To enable the ScrollViewer to perform pixel based scrolling you need to set the can content scroll to false.

The visibillity of the two scroll bars are controlled independently. I have hidden the vertical scroll bar in the one bellow.

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <ScrollViewer CanContentScroll="False" Margin="5,25,5,0" Grid.Row="2" HorizontalScrollBarVisibility="Auto"  VerticalScrollBarVisibility="Hidden">
        <TextBlock MaxHeight="500" Height="Auto" Width="Auto" VerticalAlignment="Top" Name="TextBlock_Results"
                  Text="a"/>
    </ScrollViewer>

</Grid>

Upvotes: 1

Related Questions