Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C# — Custom Xamarin.Forms renderer for TableView to hide empty cells at the bottom
// NoEmptyRowsTableViewRenderer.cs
//
// No Rights Reserved
// http://creativecommons.org/publicdomain/zero/1.0/
//
// Assume you have `MyProject.MyTableView` sublass of
// `Xamarin.Forms.TableView` and want to hide extra
// empty rows at the bottom. All you need on iOS is to set
// `TableFooterView` to empty `UIView` in custom renderer.
//
// Will work for ListView, just replace TableViewRenderer with
// ListViewRenderer.
//
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using UIKit;
using CoreGraphics;
[assembly: ExportRenderer(typeof(MyProject.MyTableView),
typeof(MyProject.iOS.NoEmptyRowsTableViewRenderer))]
namespace MyProject.iOS
{
public class NoEmptyRowsTableViewRenderer : TableViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.TableFooterView = new UIView(CGRect.Empty);
}
}
}
}
@VansW

This comment has been minimized.

Copy link

@VansW VansW commented Nov 29, 2018

Hi,

Do you have any such renderer for android as well? How do we hide empty rows in android?

Thanks,
Vans

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment