里面LongListSelector水平列表里面、水平、列表、LongListSelector

2023-09-11 08:00:57 作者:繁花绚烂不及你的美

我试着去接近以下LongListSelector项目:

Im trying to approach following LongListSelector item:

List item text
SubItem 1 SubItem 2 SubItem 3

因此​​,列表项有一行文字(列表项文本),并嵌套水平列表(子项目1子项2 ...)。

So the list item has one line of text ("List item text") and nested horizontal list (SubItem 1 SubItem 2...).

我试图建立这个用的ItemTemplate与数据模板等,但不能嵌套列表干活。

I have tried to build this using ItemTemplate with data template etc but can not get nested list workin.

我的数据源是格式如下:

My source data is in following format:

public class Data
{
    public string title{ get; set; }
    public List<SubItem> SubItems{ get; set; }

}

所有的例子都欢迎:)

All examples are welcome :)

推荐答案

您可以定义 ItemsPanel 要么WP工具包的 WrapPanel中或只是&LT; StackPanel的方向=横向/&GT;

You can define ItemsPanel to either WP Toolkit's WrapPanel or just <StackPanel Orientation="Horizontal" />

<phone:LongListSelector ItemsSource="{Binding Data}">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Title}" />
                <ListBox ItemsSource="{Binding SubItems}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding SubItemTitle}" Margin="0,0,12,0" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>

您可以看到我的内部列表中使用列表框,因为据我所知, LongListSelector 不公开的

You can see I am using ListBox in the inner list because to my knowledge LongListSelector doesn't expose that.