I would like to achieve the above. At present and can use the RepeaterView in XAML just fine, it's an excellent addition, thank you XLabs.
Now I would like to nest another RepeaterView within the ItemTemplate of the outer RepeaterView. However when I do so All I see are the items from the innermost Repeater.
Here is my code-behind and data
public partial class TestPage : ContentPage
{
public TestPage()
{
InitializeComponent();
BindingContext = CreateContext();
}
private ObservableCollection<RootItem> CreateContext()
{
ObservableCollection<RootItem> result = new ObservableCollection<RootItem>();
for (int i = 0; i < 10; i++)
{
RootItem rootItem = new RootItem() { Text = string.Format("Root Item {0}", i) };
for (int m = 0; m < 5; m++)
{
rootItem.ChildItems.Add(new ChildItem(rootItem) { Text = string.Format("ChildItem {0}.{1}", i, m) });
}
result.Add(rootItem);
}
return result;
}
}
public class RootItem
{
public RootItem()
{
ChildItems = new List<ChildItem>();
}
public string Text { get; set; }
public virtual IList<ChildItem> ChildItems { get; private set; }
}
public class ChildItem
{
public ChildItem(RootItem rootItem)
{
RootItem = rootItem;
}
public RootItem RootItem { get; private set; }
public string Text { get; set; }
}
Here is my XAML (I have omitted the local namespaces)
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms">
<ScrollView>
<Label Text="Sample List" FontSize="Large"/>
<!-- Display each RootItem -->
<controls:RepeaterView x:TypeArguments="m:RootItem" ItemsSource="{Binding}">
<controls:RepeaterView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Text}"/>
<!-- Display the ChildItems of the current RootItem -->
<controls:RepeaterView x:TypeArguments="m:ChildItem" ItemsSource="{Binding ChildItems}">
<controls:RepeaterView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Text}" HorizontalOptions="End"/>
</ViewCell>
</DataTemplate>
</controls:RepeaterView.ItemTemplate>
</controls:RepeaterView>
</ViewCell>
</DataTemplate>
</controls:RepeaterView.ItemTemplate>
</controls:RepeaterView>
</ScrollView>
</ContentPage>
Can anyone help please?
Many thanks