2013-04-25 43 views
4

好... this解決方案並不能幫助的TextBlock TextWrapping不換#2

XAML是這裏

<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> 

回答

6

嗯,你TextBlock並不需要,因爲你指定Width作爲Auto爲它的包裝ColumnDefinition它允許它採取所需的所有Width以適應內容,即使以溢出爲代價。你要麼需要設置列寬爲「*」,以允許TextWrapping踢時請求寬度超過允許或手動使用結合樣

<TextBlock Name="tbText" Grid.Row="1" MaxWidth="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}, Path=ActualWidth}" Text="{Binding Path=Data}" TextWrapping="Wrap" /> 
11
The following will helps for text wrapping: 

<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
+0

這個完美工作,感謝力就可以了MaxWidth噸 – 2017-01-28 11:58:10