문제

I want to scroll text in my textblock which is too long. My code:

<ScrollViewer VerticalScrollBarVisibility="Auto" Height="62" Margin="28,263,291,135">
      <TextBlock Name="about" Height="42" TextWrapping="WrapWithOverflow" Text="sth" Width="330" />
</ScrollViewer>

Longer text I put into textblock in my code, but then bar doesn't show and I can't scroll... What I'm doing wrong? Thx for any help...

도움이 되었습니까?

해결책

Yes the problem occurs because u have set both height and width to your textbox. Set either one of them. The reason being Scrollviewer helps to scroll only when the height or width required by the textBlock/control is not available and then it provides scroll bar to see the content. since the height and width of the textbox(since explicitly set )is within the range of the scroll viewer, it doesnt provible scrollbar. Most of the people like to have vertical scroll bar hence remove height from text box and now try

the code:

<ScrollViewer VerticalScrollBarVisibility="Auto" Height="62" Width="330" Margin="28,263,291,135">
  <TextBlock Name="about" TextWrapping="WrapWithOverflow" Text="sth" Width="330" />

다른 팁

You need to add a stackpanel

        <ScrollViewer HorizontalScrollBarVisibility="Auto">
            <StackPanel Height="62" Margin="28,263,291,135">
                <TextBlock Name="about" Height="42" TextWrapping="WrapWithOverflow" Text="sth" Width="330" />
            </StackPanel>
        </ScrollViewer>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top