Created
August 3, 2015 13:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Do you have any such renderer for android as well? How do we hide empty rows in android?
Thanks,
Vans