We are migrating an XF app to MAUI. In XF you cannot add a Footer to a TableSection or Table. This is still not possible to do in MAUI so I need to migrate our custom TableView control and Renderers.
It was my understanding that Renderers were gone but looking at the MAUI repo in GitHub
there seem to live on inside the Handlers.Compatibility
namespace.
Our Xamarin Forms Renderer looked like this
public class BreatheTableViewRenderer : TableViewRenderer
{
/// <summary>
/// Raises the <see cref="E:ElementChanged" /> event.
/// </summary>
/// <param name="e">The <see cref="ElementChangedEventArgs{TableView}"/> instance containing the event data.</param>
protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
{
base.OnElementChanged(e);
if (this.Control == null)
{
return;
}
var tableView = this.Control as UITableView;
var formsTableView = this.Element as TableView;
tableView.WeakDelegate = new BreatheTableViewModelRenderer(formsTableView);
}
private class BreatheTableViewModelRenderer : TableViewModelRenderer
{
private BreatheTableView view;
public BreatheTableViewModelRenderer(TableView model)
: base(model)
{
this.view = model as BreatheTableView;
}
protected BreatheTableView BreatheTableView { get => this.view; private set => this.view = value; }
public override UIView GetViewForFooter(UITableView tableView, nint section)
{
// Do we have a TableView Footer and if so is this is the last section
if (this.BreatheTableView.FooterText != null && section == tableView.NumberOfSections() - 1)
{
// ... if it is use that last section to display the footer
return this.GetViewForTableFooter(this.BreatheTableView.FooterText);
}
TableSection tblSection = this.View.Root[(int)section];
string sectionFooterText = BreatheTableView.GetSectionFooterText(tblSection);
if (string.IsNullOrEmpty(sectionFooterText) == false)
{
return this.GetViewForTableFooter(sectionFooterText);
}
return null;
}
private UIView GetViewForTableFooter(string text)
{
var footerView = new UITextView()
{
Text = text,
Font = UIFont.PreferredFootnote,
TextContainerInset = new UIEdgeInsets(5, 10, 5, 10),
TextColor = UIColor.LightGray,
BackgroundColor = UIColor.Clear,
Editable = false,
};
if (this.BreatheTableView.FooterAlignment == TextAlignment.Start)
{
footerView.TextAlignment = UITextAlignment.Left;
}
else if (this.BreatheTableView.FooterAlignment == TextAlignment.Center)
{
footerView.TextAlignment = UITextAlignment.Center;
}
else if (this.BreatheTableView.FooterAlignment == TextAlignment.End)
{
footerView.TextAlignment = UITextAlignment.Right;
}
return footerView;
}
}
}
I cannot see how to do the MAUI equivalent of
tableView.WeakDelegate = new BreatheTableViewModelRenderer(formsTableView);
- How do I implment my own
GetViewForFooter
- Are renderers gone in MAUI?