我用 WrapPanel 将我的 ItemsControl 设置为:
<ItemsControl Grid.Row="1" Height="200" Width="420" HorizontalAlignment="Center" Name="itemsMarks" VerticalAlignment="Top">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Margin="1"
VerticalAlignment="Center"
Source="Images/markg.png"
Width="70"
Height="70" />
<TextBlock TextWrapping="Wrap" Foreground="Black" Text="{Binding timestamp}" FontSize="14" HorizontalAlignment="Center" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我的数据是
private class mark_item
{
public mark_item()
{
this.timestamp= "";
}
public string timestamp { get; set; }
}
private List<mark_item> marks;
itemsMarks.ItemsSource = marks;
列表标记已正确创建,WrapPanel 实际上包含列表中的项目数,但 TextBlock 没有设置其 Text 属性。
我错过了什么?
谢谢