Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

custom listview with 100+ items disappears

$
0
0

Hello again!

Ive have create a lot of custom layout to an app that im working on, look at the attachment..

I've been creating a custom listview by extending Layout, and a class that can collapse the grouping, well like a treeview in wpf.

It's working like it should, but when my list get like 104 to be exact, and when i scroll up and down, then list(the one with names) and the groupname disappears. It will reappear when I enter another view and go back to the previous view.

The view with names/group names is a singleton.

I've have tried different things in my own classes and in xaml code..

Any ideas?

` public class CustomListView : Layout
{
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create<CustomListView, IEnumerable>(p => p.ItemsSource, null);
public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create<CustomListView, DataTemplate>(p => p.ItemTemplate, null);

    public IEnumerable ItemsSource
    {
        get
        {
            return (IEnumerable)GetValue(ItemsSourceProperty);
        }
        set
        {
            SetValue(ItemsSourceProperty, value);
        }
    }

    public DataTemplate ItemTemplate
    {
        get
        {
            return (DataTemplate)GetValue(ItemTemplateProperty);
        }
        set
        {
            SetValue(ItemTemplateProperty, value);
        }
    }
    public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;

    protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        CreateChildren();
    }

    private void CreateChildren()
    {
        if (ItemsSource != null && ItemTemplate != null && Children.Count() == 0)
        {
            var enumerator = ItemsSource.GetEnumerator();
            while (enumerator.MoveNext())
            {
                var view = (View)ItemTemplate.CreateContent();
                view.BindingContext = enumerator.Current;

                view.GestureRecognizers.Add(new TapGestureRecognizer()
                {
                    Command = new Command(() =>
                    {
                        ItemSelected(view, new SelectedItemChangedEventArgs(view.BindingContext));
                    })
                });

                Children.Add(view);
            }
        }
    }

    protected override SizeRequest OnSizeRequest(double widthConstraint, double heightConstraint)
    {
        var totalHeight = Children.Sum(child => child.GetSizeRequest(widthConstraint, heightConstraint).Request.Height);
        return new SizeRequest(new Size(widthConstraint, (totalHeight)));
    }

    protected override void LayoutChildren(double x, double y, double width, double height)
    {
        totalPadding = 0; 
        double totalY = 0;
        foreach (View child in Children)
        {
                SizeRequest request = child.GetSizeRequest(width, height);
                var h = height < request.Request.Height ? height : request.Request.Height;
                LayoutChildIntoBoundingRegion(child, new Rectangle(x, totalY, width, h));
                totalY += h;

        }
    }
}`

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>