在Silverlight 4中水平显示项目列表

Pha*_* PV 1 c# web-applications silverlight-4.0

我想在silverlight 4页面中水平显示产品列表.产品列表将动态获取.我展示的Foreach产品我需要显示产品图片,名称和价格.如果有人对此有任何想法,请告诉我.

Fyo*_*kin 6

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

然后,您可以使用ItemTemplate指定每个产品的显示方式.您没有详细说明您想要如何安排产品以及用于表示产品的数据结构,因此我只使用了一个简单的模式,您可以对其进行修改.

码:

    <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>
Run Code Online (Sandbox Code Playgroud)