views:

170

answers:

1

I want to display a list of products horizontally in silverlight 4 page . The list of products will be obtained dynamically. Foreach product i show i need to dispaly the product image,name and its price. Please let me know if anyone had thougts on this.

+4  A: 

Use ListBox. Then use it's ItemsPanel property to specify StackPanel with Orientation=Horizontal.

Then you specify how each product should be shown by using ItemTemplate. You didn't specify how exactly you want to arrange your product and what data structure you use to represent it, so I just used a simple pattern, which you can modify.

Code:

    <ListBox>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>

        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Image Source="{TemplateBinding ImageUrl}"/>
                    <StackPanel Orientation="Vertical">
                        <TextBlock Text="{TemplateBinding Name}"/>
                        <TextBlock Text="{TemplateBinding Price}"/>
                    </StackPanel>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
Fyodor Soikin