I'm trying to use grouped style in iOS UITableView and created a custom ListViewRenderer. The grouped style worked, but the PullToRefresh stop to work. I tested and when I don't use my custom renderer, the PullToRefresh works, but when I use the custom renderer, Pull To Refresh doesn't work.
Can anyone help me?
Here is my renderer:
public class CustomTableViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (Control != null && e.NewElement != null)
{
Control.TableFooterView = new UIView(CGRect.Empty);
if (e.NewElement.IsGroupingEnabled)
{
var groupedTableView = new UITableView(Control.Frame, UITableViewStyle.Grouped);
groupedTableView.Source = Control.Source;
if (e.NewElement.IsPullToRefreshEnabled)
{
groupedTableView.RefreshControl = Control.RefreshControl;
}
SetNativeControl(groupedTableView);
}
}
}
}
Here is my xaml:
<ContentPage.Content>
<AbsoluteLayout>
<ListView x:Name="ListViewPacientes"
ItemsSource="{Binding PacientesAgrupados}"
GroupDisplayBinding="{Binding Key}"
IsGroupingEnabled="true"
HasUnevenRows="True"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsBusy}"
RefreshCommand="{Binding LoadPacientesCommand}"
IsEnabled="{Binding CanNavigate}">
<ListView.GroupHeaderTemplate>
<OnPlatform x:TypeArguments="DataTemplate">
<OnPlatform.Android>
<DataTemplate>
<ViewCell>
<customViews:GroupHeaderView/>
</ViewCell>
</DataTemplate>
</OnPlatform.Android>
</OnPlatform>
</ListView.GroupHeaderTemplate>
<ListView.Behaviors>
<behaviors:EventToCommandBehavior
EventName="ItemTapped"
Command="{Binding PacienteSelectCommand}"
EventArgsConverter="{StaticResource ItemToObject}"/>
</ListView.Behaviors>
<ListView.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="Android" Value="{StaticResource margemPagina}"/>
</OnPlatform>
</ListView.Margin>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.Height>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="Android" Value="56"/>
</OnPlatform>
</ViewCell.Height>
<ContentView>
<ContentView.BackgroundColor>
<OnPlatform x:TypeArguments="Color" iOS="White"/>
</ContentView.BackgroundColor>
<RelativeLayout>
<Label
Text="{Binding Nome}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1.0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}"
FontSize="{StaticResource fontSize_textoPrimario}"
TextColor="{StaticResource cor_textoPrimario}"
XAlign="Start"
YAlign="End"
LineBreakMode="TailTruncation">
<Label.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="18, 4, 0, 0"/>
</OnPlatform>
</Label.Margin>
</Label>
<Label
Text="{Binding InfoPaciente}"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1.0}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.5}"
FontSize="{StaticResource fontSize_textoSecundario}"
TextColor="{StaticResource cor_textoSecundario}"
XAlign="Start"
YAlign="Start"
LineBreakMode="TailTruncation">
<Label.Margin>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="18, 6, 0, 4"/>
</OnPlatform>
</Label.Margin>
</Label>
</RelativeLayout>
</ContentView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ContentView
AbsoluteLayout.LayoutBounds="1, 1, 100, 100"
AbsoluteLayout.LayoutFlags="XProportional,YProportional">
<OnPlatform x:TypeArguments="View">
<OnPlatform.Android>
<customViews:FloatingActionButtonView
Elevation="12"
BackgroundTint="{StaticResource Accent}"
ImageName="ic_add.png"
Size="Normal"
Command="{Binding AdicionarCommand}"/>
</OnPlatform.Android>
</OnPlatform>
</ContentView>
</AbsoluteLayout>
</ContentPage.Content>