locked
How to use HandleCellPropertyChanged in TextCellRenderer RRS feed

  • Question

  • User372721 posted

    I am writing extended text-cell renderer. I have called HandlePropertyChanged of TextCellRenderer.

            ctvcell.Cell = textCell;  // where ctvcell is CellTableViewCell and textCell is TextCell
            textCell.PropertyChanged += ctvcell.HandlePropertyChanged;
            ctvcell.PropertyChanged = this.HandlePropertyChanged;
    

    However nothing changes when my Text/Detail values change in viewModel. I see that in latest Xamarin.Forms.Platform.iOS->class TextCellRenderer : CellRenderer HandlePropertyChanged() is all commented out

    protected virtual void HandlePropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            //keeping this method for backwards compatibility 
            //as the the sender for this method is a CellTableViewCell
        }
    

    So I decided to use HandleCellPropertyChanged(), however when I plugin HandleCellPropertyChanged() in code above i.e.

    ctvcell.PropertyChanged = this.HandleCellPropertyChanged;
    

    It is crashing. Is there anything else I need to do? Why isn't i call default HandleCellPropertyChanged() to smoothly update the properties?

    Thursday, October 18, 2018 11:38 AM

All replies

  • User369979 posted

    I'm confused about what you want to achieve? For the Renderer class:

    public class TextCellRendererForiOS : TextCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            item.PropertyChanged += Item_PropertyChanged;
            return base.GetCell(item, reusableCell, tv);
        }
    
        private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
    
        }
    
        protected override void HandlePropertyChanged(object sender, PropertyChangedEventArgs args)
        {
    
        }
    }
    

    When your view model's(this viewModel should implement INotifyPropertyChanged interface) text has been changed, both HandlePropertyChanged and Item_PropertyChanged events will be triggered. You haven't show your ctvcell class. And if you want to handle this property changed event in that class, moving the Item_PropertyChanged to that class will be approach.

    Friday, October 19, 2018 9:39 AM
  • User372721 posted

    Instead of HandlePropertyChanged() I want to use HandleCellPropertyChanged of TextCellRenderer(). There is already part of TextCellRenderer{} class, but somehow cannot be used. I am looking for right way to use this method. I need not override everytime as I want to play with already existing properties.

    Thursday, October 25, 2018 5:16 AM
  • User369979 posted

    HandleCellPropertyChanged event can be used after xamarin.Forms 3.2.0+. Before that version we used HandlePropertyChanged. And if you want to trigger ctvcell.PropertyChanged method, just place code in that method like:

    protected override void HandleCellPropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        //Place your code here
        //Ctvcell ctvcell = new Ctvcell();
        //ctvcell.PropertyChanged(sender, args);
    }
    
    Thursday, October 25, 2018 5:50 AM