我创建了一个数据模板,该数据模板以Border为根,而网格为Border的子级。我将网格细分为多个单元,并在其中一个单元中放置了一个文本块。但奇怪的是,此文本块没有包装其内容。
以下xaml代码中所示的TextBlock放置在一个单元格中,该单元格的宽度是动态的,但不会自动包裹。
有人可以告诉我我的xaml代码是什么问题吗?
<DataTemplate x:Key="dtConversation" DataType="{x:Type model:Conversation}">
<Border Padding="10 5"
Name="brd"
Height="70"
Background="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border Height="40"
Width="40"
CornerRadius="20"
Background="#373A3E"
VerticalAlignment="Top"
Margin="0 5 5 5"
Padding="3"
>
<Path Stretch="Uniform"
Fill="#fff"
Width="24"
Height="24"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="{Binding Type, Converter={StaticResource typeToIconConverter}}"
/>
</Border>
<Grid Grid.Column="1"
Background="Yellow">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding DestinataireName}"
FontWeight="DemiBold"
FontSize="16"
Margin="0 0 10 0"
Name="txtDestinataire"/>
<TextBlock Text="{Binding LastMessage.Date, Converter={StaticResource shortDateConverter}}"
Foreground="#777"
FontSize="11"
Grid.Column="1"
HorizontalAlignment="Right"
Name="txtDate"
/>
</Grid>
<TextBlock Grid.Row="1"
Foreground="#999"
Text="{Binding LastMessage.Content}"
TextWrapping="Wrap"
MaxHeight="40"
TextTrimming="CharacterEllipsis"
Name="txtContent"/>
</Grid>
</Grid>
</Border>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Value="True">
<Setter TargetName="brd" Property="Background" Value="#50AAAAAA" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>