xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Enhancement] Bindable Repeater control #1718

Closed hartez closed 6 years ago

hartez commented 6 years ago

Rationale

Forms does not currently contain a control which displays items from a bound items source in a non-scrollable container.

Implementation

Attached properties targeting Layout will be added to support an ItemsSource and ItemsTemplate. Setting these properties will add the templated items to the target layout.

public static class BindableLayout
{
    public static readonly BindableProperty ItemsSourceProperty =
        BindableProperty.Create("ItemsSource", typeof(IList), typeof(Layout), default(IList));

    public static readonly BindableProperty ItemTemplateProperty =
        BindableProperty.Create("ItemTemplate", typeof(DataTemplate), typeof(Layout);
}

The ItemTemplate is responsible for converting the objects in the ItemsSource into View objects.

Setting the ItemsSource will clear out any existing children and update the Children collection to match the source.

Backward Compatibility

These are new properties, so backward compatibility is likely not an issue.

Difficulty: Moderate

StephaneDelcroix commented 6 years ago

ItemsSource and ItemTemplate should be attached bindable properties, so it could be applied to Grid, StackLayout, Flex, ...

hartez commented 6 years ago

I have updated the proposed spec to reflect the attached property suggestions from GalaxiaGuy and StephaneDelcroix.

hartez commented 6 years ago

RE: https://github.com/xamarin/Xamarin.Forms/issues/1718#issuecomment-394780832

After careful consideration, CollectionView will not cover the scenario from this proposal: https://github.com/xamarin/Xamarin.Forms/issues/3172#issuecomment-424413234

So this proposal is back on the table.

GalaxiaGuy commented 6 years ago

@hartez Typo on the updated spec, both bindable properties are called ItemTemplate. :)

hartez commented 6 years ago

@hartez Typo on the updated spec, both bindable properties are called ItemTemplate. :)

D'oh! Thanks, fixed.