views:

688

answers:

2

Can anybody please help me? I need to bind CLR Objects to a WrapPanel in SILVERLIGHT. What should be displayed in the end is a couple of Image Thumbnails with their description (Text). I know how to do it with a ListBox, but I need it to be a WrapPanel, so my Thumbs will be displayed horizontally and break into a new raw... and so on.

A: 

In this case you still want your control to be a ListBox, but you set the ItemsPanel of the ListBox to be a WrapPanel such as

        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel IsItemsHost="True" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

It will then display the items horizontally and wrap at the end of the line.

cosullivan
Thanx for that, but I'm not really sure how to use this. I mean, my XAML code doesn't look anything like this... not even close. <ItemsPanelTemplate> causes errors.
Sorry, you will need to download the Silverlight toolkit also as the WrapPanel is not part of the standard Silverlight framework.www.codeplex.com/Silverlightyou XAML would then look like<ListBox> <ListBox.ItemsPanel> <ItemsPanelTemplate> <toolkit:WrapPanel /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox>to create a list box.
cosullivan
Yeah, I sure did install the toolkit. According to the code you send me, everything looks ok, but as soon as I try to bind the content, nothing visible happens. I also tried to copy/paste my item code into the WrapPanel, but "ItemTemplate" and "ItemSource" are not recognized and cause errors. Everything looks perfect in a ListBox, but I still need it in a WrapPanel (Horizontal first).Thanx for your help though...
A: 

Problem solved. I had to replace the StackPanel INSIDE the ListBox with the WrapPanel. Very simple... you just have to know it!