Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Customising TableView section header

$
0
0

There is a logic in TableViewRenderer on iOS (and probably other platforms) implementing custom section header rendering.
But current implementation of TableView or more specifically TableModel always return null for section header. TableModel is internal, so it cannot be extended.

Any plans on this kind of customisation?

UPD:
As a current workaround I'm using custom TableViewModelRenderer implementation (using decorator pattern):

public class CustomTableViewModelRenderer : TableViewModelRenderer
{
    public CustomTableViewModelRenderer(TableView table, TableViewModelRenderer renderer)
         : base(table)
    {
        _renderer = renderer;
    }

    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
    {
        return _renderer.GetCell(tableView, indexPath);
    }

    // override all TableViewModelRenderer members here...

   public override UIView GetViewForHeader(UITableView tableView, int section)
   {
        // custom logic here
   }
}

Then define custom TableViewRenderer as usually rewriting Source property:

public class CustomTableViewRenderer : TableViewRenderer
{
    protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement == null)
        {
            var tableView = Control;
            tableView.Source = new FinesListModelRenderer(Element, (TableViewModelRenderer)tableView.Source);
        }
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles