在 Xamarin.forms xaml 中的列表中列出
List within List in Xamarin.forms xaml
我有一本字典,其中的值是字符串列表。在我的 xaml 中,我将字典绑定到一个列表,并在该列表中打印出密钥。然后我想打印出每个键的值列表。我应该将什么绑定到值列表以及我应该将什么绑定到值标签?
这是我的 xaml:
<ListView x:Name ="QuoteListView" ItemsSource ="{Binding dict}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate >
<ViewCell >
<ViewCell.View >
<StackLayout>
<StackLayout Orientation="Horizontal" Padding="10">
<Label Text ="{Binding Key}" FontSize="10" FontAttributes="Bold" TextColor="White" />
</StackLayout>
<StackLayout Orientation="Horizontal" Padding="10">
<ListView x:Name ="QuoteTextListView" ItemsSource ="{Binding }" HasUnevenRows="True">
<Label Text ="{Binding }" FontSize="10" TextColor="White"/>
</ListView>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这就是我想要实现的:
名称 1
"Quote 1 text"
"Quote 2 text"
名称 2
"Quote 1 text"
"Quote 2 text"
...
我建议使用 ListView
分组。您可以将字典变成 2 个列表。 ListView
可以找到分组信息 here。
基本上,您将创建一个对象来存储报价字符串列表。然后,您获取该对象并将其放入代表名称列表的另一个对象中。如果您有任何问题,请告诉我。
我有一本字典,其中的值是字符串列表。在我的 xaml 中,我将字典绑定到一个列表,并在该列表中打印出密钥。然后我想打印出每个键的值列表。我应该将什么绑定到值列表以及我应该将什么绑定到值标签?
这是我的 xaml:
<ListView x:Name ="QuoteListView" ItemsSource ="{Binding dict}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate >
<ViewCell >
<ViewCell.View >
<StackLayout>
<StackLayout Orientation="Horizontal" Padding="10">
<Label Text ="{Binding Key}" FontSize="10" FontAttributes="Bold" TextColor="White" />
</StackLayout>
<StackLayout Orientation="Horizontal" Padding="10">
<ListView x:Name ="QuoteTextListView" ItemsSource ="{Binding }" HasUnevenRows="True">
<Label Text ="{Binding }" FontSize="10" TextColor="White"/>
</ListView>
</StackLayout>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这就是我想要实现的:
名称 1
"Quote 1 text"
"Quote 2 text"
名称 2
"Quote 1 text"
"Quote 2 text"
...
我建议使用 ListView
分组。您可以将字典变成 2 个列表。 ListView
可以找到分组信息 here。
基本上,您将创建一个对象来存储报价字符串列表。然后,您获取该对象并将其放入代表名称列表的另一个对象中。如果您有任何问题,请告诉我。