tags:

views:

381

answers:

1

My list box has, amongst other things a description field in it which can be quite long. Instead of having a horizontal scroll bar I want to word wrap it. It works if I set the MaxWidth but since the ListBox changes size I don't want to hard code the value.

What's the best way to do this?

EDIT: The description is in a TextBlock.

Simplified XAML (Removed unnessesary stuff, still shows problem:

         <ListBox BorderThickness="0" Padding="5" Name="lstTasks">
            <ListBox.ItemsSource>
                <Binding Source="{StaticResource dataTasks}"/>
            </ListBox.ItemsSource>

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <TextBlock Text="{Binding Path=RequestDescription}" TextTrimming="WordEllipsis" TextWrapping="Wrap" Height="60" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
+3  A: 

Try forcing the width of your ListBoxItems to be the width of the ListBox:

<ListBox
     Name="lstTasks"
     BorderThickness="0"
     Padding="5"
     HorizontalContentAlignment="Stretch">

Also you might try disabling horizontal scrolling:

<ListBox
     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
     ...>
Matt Hamilton
Thanks, disabling the Scroll Bar fixed it instantly.
Chris McGrath