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

Custom Cell Renderer issue

$
0
0

I have been having this issue since I've started working on a project that requires a custom renderer, in January.

Our goal is to have customized list views - the list items must display four important information, in a 2 row, 3 column grid:
- row 1 and row 2 in column 1 merged, displaying a single, big number (like in ImageCell)
- row 1 in column 2 and 3 displaying a text with medium font size
- row 2 in column 2 displaying a text with small font size
- row 2 in column 3 displaying a text with small font size, aligned to the right

Now, for this I've tried ViewCell, but given how it is rendered and generated, it is extremely slow (compared to e.g. TextCell, with the same layout, it is 6-7x slower).

The code is the following:

The PCL class:
public class ExtendedCell : Cell
{
public static readonly BindableProperty BigNumProperty = BindableProperty.Create<ExtendedCell, String>(p => p.BigNum, default(String));
public String BigNum
{
get { return (String)GetValue(BigNumProperty); }
set { SetValue(BigNumProperty, value); }
}

            public static readonly BindableProperty TextProperty = BindableProperty.Create<ExtendedCell, String>(p => p.Text, default(String));

            public String Text
            {
                get { return (String)GetValue(TextProperty); }
                set { SetValue(TextProperty, value); }
            }

            public static readonly BindableProperty DetailProperty = BindableProperty.Create<ExtendedCell, String>(p => p.Detail, default(String));

            public String Detail
            {
                get { return (String)GetValue(DetailProperty); }
                set { SetValue(DetailProperty, value); }
            }

            public static readonly BindableProperty DateProperty = BindableProperty.Create<ExtendedCell, String>(p => p.Date, default(String));

            public String Date
            {
                get { return (String)GetValue(DateProperty); }
                set { SetValue(DateProperty, value); }
            }



            public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create<ExtendedCell, Color>(p => p.BackgroundColor, default(Color));

            public Color BackgroundColor
            {
                get { return (Color)GetValue(BackgroundColorProperty); }
                set { SetValue(BackgroundColorProperty, value); }
            }

            public static readonly BindableProperty ForegroundColorProperty = BindableProperty.Create<ExtendedCell, Color>(p => p.ForegroundColor, default(Color));

            public Color ForegroundColor
            {
                get { return (Color)GetValue(ForegroundColorProperty); }
                set { SetValue(ForegroundColorProperty, value); }
            }


    public ExtendedCell()
    {
    }
}

The WP8 renderer:

    [assembly: ExportCell(typeof(ExtendedCell), typeof(ExtendedCellRenderer))]
    public class ExtendedCellRenderer : ViewCellRenderer  //ICellRenderer, IRegisterable
    {
            public ExtendedCellRenderer()
            {

            }

            public override System.Windows.DataTemplate GetTemplate(Cell cell)
            {
                return (System.Windows.DataTemplate)App.Current.Resources["ExtendedCellTemplate"];
            }
}

The Android renderer:
[assembly:ExportCell(typeof(ExtendedCell),typeof(ExtendedCellRenderer))]
class ExtendedCellRenderer : ViewCellRenderer
{
private Android.Views.View extendedCell;

            static ExtendedCellRenderer()
            { 

            }


            protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
            {
                var cell = (ExtendedCell)item;
                var view = convertView;

                if (view == null)
                {
                    view = (context as Activity).LayoutInflater.Inflate(Resource.Layout.ExtendedCellLayout, null);
                }
                else
                {

                }

                view.FindViewById<TextView>(Resource.Id.bigNumText).Text = cell.BigNum;
                view.FindViewById<TextView>(Resource.Id.subjecText).Text = cell.Text;
                view.FindViewById<TextView>(Resource.Id.topicText).Text = cell.Detail;
                view.FindViewById<TextView>(Resource.Id.dateText).Text = cell.Date;


                return view;
            }

            protected override void OnCellPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                base.OnCellPropertyChanged(sender, e);

            }
}

On WP, the code runs, and it displays a TextCell instead (on WP, regular Cell's are set to use the TextCellRenderer). On Android, it defaults to CellRenderer, which in turn, displays nothing.

The code above represents a new state, where I based my CellRenderers on the ViewCellRenderer class (previously it was based on CellRenderer and ICell + IRegisterable).

What can be the issue? Why is it not working, did I miss a step?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>