0
votes

I try to create a listbox in my Windows Phone app. I tried to create a custom datatemplate for it. In a lot of sample I saw similar to this simple listbox:

<ListBox Width="350">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Test text 1" />
                <TextBlock Text="Test text 2" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

This is very simple isn't it? However the UI shows nothing. I can put textblocks and other control on the grid. I also tried using binding and itemssource but still nothing.

If I'm not using datatemplate just a simple textblock it shows the textblock:

            <ListBox Width="350">
                        <TextBlock Text="haha" />
        </ListBox>

Does anyone have any idea what do I wrong?

Thanks!

1

1 Answers

0
votes

I think you need to bind the ItemSource of the listbox to something with items in it.

The second sample shows up because you are setting the content of the listbox directly.