display list of items horizontally in Silverlight 4

北城余情 提交于 2020-01-05 06:09:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!