I simplified this only to show what is needed to demonstrate the problem, which means that although 8 elements are explicitly on the list, they have no content, i.e. The "name" is not displayed, they are just spaces. If I set a breakpoint right after the ItemSource was set, I see that the source was correctly populated with the collection, so I assume that something should be wrong with my xaml. Here is the code and xaml:
public partial class MainPage : UserControl { private ObservableCollection<ToolboxItem> ToolboxItems; public MainPage() { InitializeComponent(); InitToolboxItems(); lstToolbox.ItemsSource = ToolboxItems; } private void InitToolboxItems() { ToolboxItems = new ObservableCollection<ToolboxItem>(); ToolboxItems.Add(new ToolboxItem(name: "Item1")); ToolboxItems.Add(new ToolboxItem(name: "Item2")); ToolboxItems.Add(new ToolboxItem(name: "Item3")); ToolboxItems.Add(new ToolboxItem(name: "Item4")); ToolboxItems.Add(new ToolboxItem(name: "Item5")); ToolboxItems.Add(new ToolboxItem(name: "Item6")); ToolboxItems.Add(new ToolboxItem(name: "Item7")); ToolboxItems.Add(new ToolboxItem(name: "Item8")); } public struct ToolboxItem { public String Name; public ToolboxItem(String name) { Name = name; } } } <Grid x:Name="LayoutRoot" Background="White"> <ListBox Name="lstToolbox" Width="200" Height="280"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" Width="100" Height="20" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid>
descf source share