In silverlight 2.0. I have some content that i want to scroll vertically and wrap horizontally. In the controls I have a dock panel. The DockPanel’s last child, which fills it, is a ScrollViewer
<UserControl x:Class='MyProject.MyControl' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:WinControls='clr-namespace:Microsoft.Windows.Controls; assembly=Microsoft.Windows.Controls' Width='400' Height='300'> <WinControls:DockPanel LastChildFill='True'> ... <ScrollViewer x:Name='MessageScroll' HorizontalScrollBarVisibility='Hidden' VerticalScrollBarVisibility='Auto' BorderThickness='0' > <Controls:TextDisplay x:Name='TextDisplay'></Controls:TextDisplay> </ScrollViewer>
The TextDisplay control XAML looks like this:
<UserControl x:Class='MyProject.TextDisplay' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> <TextBlock x:Name='TextDisplayText' TextWrapping='Wrap'> </TextBlock> </UserControl>
What I want to happen: The TextDisplay should occupy the main area of the control, with a vertical scrollbar if the height doesn’t fit. The messages should wrap when they get too long horizontally.
The scrolling works, but now the messages don’t wrap at the right-hand edge. they just cut off. It’s not constraining the width, just hiding the HorizontalScrollBar. If I set HorizontalScrollBarVisibility=’Auto’ I can see them scrolling off to the right. How do i force it to wrap?
Try setting the HorizontalScrollBarVisibility of the ScrollViewer to Disabled (or do not specify a value as Disabled is the default) then the TextDisplay will wrap correctly and the horizontal scroll bar will not be displayed.