TextBlock TextWrapping 不换行 #2 [英] TextBlock TextWrapping not wrapping #2

查看:29
本文介绍了TextBlock TextWrapping 不换行 #2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的...所以这个解决方案没有帮助

OK... so this solution doesn't help

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>

推荐答案

好吧,您的 TextBlock 不需要换行,因为您将 Width 指定为 Auto 因为它是 ColumnDefinition,它允许它采用所有 Width 来适应内容,即使以溢出为代价.您需要将列的宽度设置为*"以允许 TextWrapping 在请求的宽度超出允许范围时启动,或者使用 Binding 手动强制 MaxWidth 在其上使用

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

这篇关于TextBlock TextWrapping 不换行 #2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆