问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/2688015/display-list-of-items-horizontally-in-silverlight-4