简体   繁体   中英

List within List in Xamarin.forms xaml

I have a ditcionary with values as lists of string. In my xaml I bind the dictionary to a list and within that list I print out the key. I then want to print out a list of value for each key. What should I bind to the Value list and what should I bind to the Value label?

Here is my 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>

This is what I want to achieve:

Name 1

"Quote 1 text"

"Quote 2 text"

Name 2

"Quote 1 text"

"Quote 2 text"

...

I would suggest using ListView Grouping. You can turn your dictionary into 2 lists. ListView Grouping info can be found here .

Basically you will create an object to store the list of Quote strings. Then you take that object and put it into another object representing the list of Names. Let me know if you have any issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM