tags:

views:

23

answers:

2

I am playing with XamlPadX and here is the code I have so far:

<ScrollViewer Name="Scroller" 
                HorizontalScrollBarVisibility="Disabled" 
                VerticalScrollBarVisibility="Auto" 
                Height="100">

    <TextBlock Name="txtLog" TextWrapping="Wrap" VerticalAlignment="Stretch" Height="100">

         Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at aliquet justo. Praesent adipiscing ante nec ipsum pellentesque semper. Proin tristique lorem eget lorem viverra pellentesque in et quam. Maecenas at varius nunc. Donec bibendum tortor non nisi aliquam ultrices. Quisque nec felis elit. Morbi ut orci a nunc malesuada accumsan sed ut metus. Praesent eu dolor et elit faucibus adipiscing ac vitae lectus. Donec elit sapien, sollicitudin sed porta ac, egestas eu odio. Cras vulputate sagittis est, sed pretium ligula dictum commodo. Sed sit amet enim ut velit bibendum gravida vitae eget diam. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Maecenas facilisis eleifend sem quis interdum.

        Nam vestibulum, tortor dictum feugiat aliquam, ligula mi commodo nisl, eget sagittis est leo a nunc. Nunc elit lacus, sodales non dictum vel, tincidunt vitae felis. Sed blandit convallis dui, nec laoreet diam volutpat eu. Sed et risus nunc. Aliquam vitae lectus a lectus ullamcorper aliquam. Donec venenatis lorem ut nulla posuere at dictum ante sodales. Nullam dictum ante bibendum leo bibendum mattis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ultricies risus sodales velit iaculis varius interdum mauris interdum. Curabitur pellentesque mattis lobortis. Quisque ornare luctus dignissim. Sed gravida consequat feugiat. Aliquam malesuada lacinia faucibus. Mauris et est ut sem imperdiet volutpat.

        Aliquam non erat nec ante sollicitudin pellentesque sit amet eu mi. Integer tempus, ipsum nec mollis faucibus, elit nisl feugiat felis, sed venenatis leo felis id quam. Cras ut porta justo. In tempor ultricies sapien, id iaculis metus blandit sit amet. Pellentesque ullamcorper, risus lacinia vehicula aliquet, risus quam luctus mauris, eu pellentesque leo enim vel turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed vel adipiscing quam. Praesent eget tortor lectus, vitae ultricies sem. Fusce cursus lorem in arcu auctor interdum. Pellentesque est arcu, lobortis quis mollis posuere, iaculis nec nisi. In sollicitudin tortor sed purus eleifend posuere. Vestibulum.

    </TextBlock>

</ScrollViewer>

The problem is the scroll bar doesn't appear even if I set a height in the TextBlock, why?

+1  A: 

Your ScrollViewer will never display a scrollbar, since it's Height is 100, and the Height of the TextBlock is also 100. The text within the TextBlock is simply overflowing out of the bounds of the control without making the control larger. If you want the TextBlock to always fill the ScrollViewer, then change the Height property on the TextBlock to MinHeight instead. If you don't care that the TextBlock may be shorter than the ScrollViewer, then just do away entirely with the Height property on the TextBlock.

md5sum
Let say I do not know the ScrollViewer size. How can I make it works. You solution works but in the real software, the Scrollviewer require to take all the place in height.
Daok
If you don't know the `Height` of the `ScrollViewer`, as long as you don't set a `Height` for the `TextBlock`, the `ScrollViewer` will start scrolling as soon as it needs to, and the `TextBlock` will automatically resize to match the size of the text it contains.
md5sum
I have removed the height of the textbox and I see the textbox having the whole height of the ScrollViewer but it still doesn't have the scroll bar. The solution to set a TextBlock height less than the ScrollViewer works but I still need to put a fixed Height...
Daok
A: 

Set Height=50 or less for scroll viewer and check

Avatar