I am using this custom renderer:
public class ExtViewCellRenderer : ViewCellRenderer
{
UITableViewCell _nativeCell;
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
_nativeCell = base.GetCell(item, reusableCell, tv);
var formsCell = item as ExtViewCell;
if (formsCell != null)
{
formsCell.PropertyChanged -= OnPropertyChanged;
formsCell.PropertyChanged += OnPropertyChanged;
}
SetTap(formsCell);
return _nativeCell;
}
void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
var formsCell = sender as ExtViewCell;
if (formsCell == null)
return;
if (e.PropertyName == ExtViewCell.NoTapProperty.PropertyName)
{
SetTap(formsCell);
}
}
private void SetTap(ExtViewCell formsCell)
{
if (formsCell.NoTap)
_nativeCell.SelectionStyle = UITableViewCellSelectionStyle.None;
else
_nativeCell.SelectionStyle = UITableViewCellSelectionStyle.Default;
}
}
I read that with a TextCellRenderer
it's no longer necessary to explicitly subscribe to property-changed-event as there is a base overridable method HandlePropertyChanged
that can be re-used in this context.
Can someone tell me if this is the case also for the ViewCellRenderer
and if so then how could I modify this code to make use of this?
I also saw code like this in another renderer:
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
var textCell = (TextCell)item;
var fullName = item.GetType().FullName;
cell = tv.DequeueReusableCell(fullName) as CellTableViewCell;
//...
But not here. Is it necessary to do this Cell = tv.DequeueReusableCell
?
I read that with a TextCellRenderer it's no longer necessary to explicitly subscribe to property-changed-event as there is a base overridable method HandlePropertyChanged that can be re-used in this context.
Yes that is correct according to its source code
protected virtual void HandlePropertyChanged(object sender, PropertyChangedEventArgs args) {
//...
}
TextCellRenderer Source
Can someone tell me if this is the case also for the ViewCellRenderer and if so then how could I modify this code to make use of this?
No it is not the case also for the ViewCellRenderer
as according to source code ViewCellRenderer is not exposing its ViewCellPropertyChanged
as it is private
void ViewCellPropertyChanged(object sender, PropertyChangedEventArgs e) {
//...
}
ViewCellRenderer Source
You could always modify it yourself and create a pull request to add that feature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With