Skip to content

Instantly share code, notes, and snippets.

@rudyryk
Created August 3, 2015 13:17
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudyryk/20dbf5cfa4a1f49382dd to your computer and use it in GitHub Desktop.
Save rudyryk/20dbf5cfa4a1f49382dd to your computer and use it in GitHub Desktop.
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
Copy link

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