TextBlock TextWrapping not wrapping #2
Asked Answered
S

2

5

OK... so this solution doesn't help

XAML is here

  <ListBox  ItemsSource="{Binding Path=ContentItems}" Background="White" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="2" Height="Auto" Width="Auto">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid Grid.Column="0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <StackPanel Grid.Row="0" Orientation="Horizontal">
                                    <Label VerticalAlignment="Center"  Margin="0,0,0,5">Start</Label><svl:TimeEditor Value="{Binding Path=FormatedStart}" Width="87"  HorizontalAlignment="Left"  Margin="2,8"  Name="dtpStart" FontSize="12"  Height="25"  VerticalAlignment="Center"     />
                                    <Label VerticalAlignment="Center"  Margin="0,0,0,5">End</Label><svl:TimeEditor Value="{Binding Path=FormatedEnd}" Width="87"  HorizontalAlignment="Left"  Margin="2,8"  Name="dtpEnd" FontSize="12"  Height="25"  VerticalAlignment="Center"     />
                                </StackPanel>                               
                                <TextBlock Grid.Row="1"  TextWrapping="Wrap"  Name="tbText" Text="{Binding Path=Data}"></TextBlock>
                            </Grid>
                            <Grid Grid.Column="1" Visibility="Collapsed">
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
Scuff answered 25/4, 2013 at 17:28 Comment(0)
R
10

Well your TextBlock does not need to wrap since your specifying Width as Auto for it's ColumnDefinition which allows it to take all the Width it needs to fit Content even at the cost of overflowing. You either need to set the Column's Width to "*" to allow the TextWrapping to kick in when requested width exceeds allowable or manually force a MaxWidth on it using a Binding like

<TextBlock Name="tbText" Grid.Row="1" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualWidth}" Text="{Binding Path=Data}" TextWrapping="Wrap" />
Rociorock answered 25/4, 2013 at 17:56 Comment(0)
P
13
The following will helps for text wrapping:

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled">
Packston answered 6/11, 2015 at 5:56 Comment(0)
R
10

Well your TextBlock does not need to wrap since your specifying Width as Auto for it's ColumnDefinition which allows it to take all the Width it needs to fit Content even at the cost of overflowing. You either need to set the Column's Width to "*" to allow the TextWrapping to kick in when requested width exceeds allowable or manually force a MaxWidth on it using a Binding like

<TextBlock Name="tbText" Grid.Row="1" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualWidth}" Text="{Binding Path=Data}" TextWrapping="Wrap" />
Rociorock answered 25/4, 2013 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.