I’ve set my ItemsControl with WrapPanel as:
<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>
my data is
private class mark_item
{
public mark_item()
{
this.timestamp= "";
}
public string timestamp { get; set; }
}
private List<mark_item> marks;
itemsMarks.ItemsSource = marks;
List marks is properly created, and WrapPanel contains actually the number of items there are in the list, but TextBlock doesn’t get its Text property set.
What am I missing?
Thanks
You need to declare your
mark_itemclass aspublic, notprivate.Data binding in Silverlight can only access
publicclasses and properties. By declaring the classprivate, you’re preventing Silverlight from being able to access it.I took your code as it is and I saw the same behaviour you described. The right number of items were appearing in the
ItemsControlbut the text was missing. I also saw the following message in the Output window in Visual Studio/Visual Web Developer Express. (I’ve omitted the stacktrace as the message itself is long enough):When I declared the class
public, the problem went away.