iOS Pull to refresh

nefgrixisnefgrixis Member ✭✭
edited August 2018 in Xamarin.Forms

I want to implement pull to refresh on a Forms project I have, but after the refresh is over, the Cells in the ListView are empty on iOS. this is what I got

<ListView x:Name="listView" Grid.Row="2" Grid.Column="0" ItemsSource="ActivityList" BackgroundColor="#D6D6D6" IsVisible="False"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.View> <custom:CustomFrame Padding="0,5,0,0" Margin="0,10,0,0" > <StackLayout> <Label Style="{StaticResource bold}" FontSize="Large" TextColor="#c4950b" Margin="10,0,0,0" x:Name="labelName" Text="{Binding Key}" /> <local1:Carousel ActList="{Binding Value}" KeyName="{Binding Key}" /> </StackLayout> </custom:CustomFrame> </ViewCell.View> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
ListView CustomRenderer
`
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizPass.iOS;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(ListView), typeof(NoBarListView))]
namespace BizPass.iOS
{
class NoBarListView : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control != null)
{
var itemCount = Control.NumberOfRowsInSection(0);
System.Diagnostics.Debug.WriteLine(itemCount);
Control.ShowsHorizontalScrollIndicator = false;
Control.ShowsVerticalScrollIndicator = false;

        }
    }
}

}
`

Frame CustomRenderer
`
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizPass.iOS;
using CoreGraphics;
using Foundation;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(BizPass.Controls.CustomFrame), typeof(CustomFrame))]
namespace BizPass.iOS
{
class CustomFrame : FrameRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);

        if(e.OldElement != null)
        {
            var rect = e.OldElement.Bounds.ToRectangleF();
            this.Draw(rect);
        }

        //Forces the element to be redrawn when coming into veiw. Specifically for upcoming list
        ContentMode = UIViewContentMode.Redraw;
    }

    //Method to draw the control
    public override void Draw(CGRect rect)
    {
        // Update shadow to match better material design standards of elevation
        Layer.ShadowRadius = 2.0f;
        Layer.ShadowColor = UIColor.LightGray.CGColor;
        Layer.ShadowOffset = new CGSize(2, 2);
        Layer.ShadowOpacity = 0.80f;
        Layer.ShadowPath = UIBezierPath.FromRect(Layer.Bounds).CGPath;
        Layer.MasksToBounds = false;
        base.Draw(rect);
    }
}

}

`

Best Answer

Answers

  • nefgrixisnefgrixis Member ✭✭

    Figured it out. Had to have the Caching strategy to RetainElement

Sign In or Register to comment.