In addition to Sven-Michael, you can enrich his code by creating a inheritance of your ListView
(if you do not already have one) and add a Delegate
to it like this:
public class AccessoryListView : ListView
{
public delegate void OnAccessoryTappedDelegate();
public OnAccessoryTappedDelegate OnAccessoryTapped { get; set; }
}
Now from your custom renderer - don't forget to set it to your new inherited ListView
- call the delegate
public class ContactListViewRenderer : ListViewRenderer, IUITableViewDelegate
{
private AccessoryListView _formsControl;
protected override void OnElementChanged(ElementChangedEventArgs<AccessoryListView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.WeakDelegate = this; // or. Control.Delegate
}
if (e.NewElement != null)
_formsControl = e.NewElement;
}
public virtual void AccessoryButtonTapped(UITableView tableView, NSIndexPath indexPath)
{
// accessory tapped
if (_formsControl.OnAccessoryTapped != null)
_formsControl.OnAccessoryTapped();
}
}
You can of course add some parameters in there to supply your shared code with more data. With this you do have some platform specific code, but you get back to your shared code 'as soon as possible' making your code more reusable.
Another sample of this with a Map control can be found here.