在 Silverlight 4 中水平显示项目列表 [英] display list of items horizontally in Silverlight 4

查看:25
本文介绍了在 Silverlight 4 中水平显示项目列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 silverlight 4 page 中水平显示产品列表.产品列表将动态获取.对于我展示的每个产品,我需要显示产品图片、名称及其价格.如果有人对此有想法,请告诉我.

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.

推荐答案

使用 ListBox.然后使用它的 ItemsPanel 属性指定具有 Orientation=Horizo​​ntal 的 StackPanel.

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

然后,您可以使用 ItemTemplate 指定每个产品的显示方式.您没有具体说明您希望如何准确地安排您的产品以及您使用什么数据结构来表示它,所以我只是使用了一个简单的模式,您可以对其进行修改.

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.

代码:

    <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>

这篇关于在 Silverlight 4 中水平显示项目列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆