xamarinmonotouch.dialogxamarin-studio

Monotouch Dialog OwnerDrawnElement - Height Size not being called


I am trying to inherit from OwnerDrawnElement (as presented in the docs). Everything seems to be working except the Height method is never called so I am not able to set the height of the cell. The Height method is never called (breakpoint never hits). I tried to force a reimplementation of IElementSizing and implemented the method again as a new method. Again, that also doesn't get hit. Here is the stripped down code

public class CustomDrawElement : OwnerDrawnElement, IElementSizing
    {
        public CustomDrawElement (UITableViewCellStyle style, string cellIdentifier) : base (style, cellIdentifier)
        {

        }

        #region implemented abstract members of OwnerDrawnElement

        public override void Draw (System.Drawing.RectangleF bounds, MonoTouch.CoreGraphics.CGContext context, MonoTouch.UIKit.UIView view)
        {
            UIColor.Blue.SetFill ();
            context.FillRect (bounds);
        }

        public override float Height (System.Drawing.RectangleF bounds)
        {
            return 220f;
        }

        #endregion

        public new float GetHeight (UITableView tableView, NSIndexPath indexPath) {
            return 220f;
        }
    }

When creating the object, I using for test purposes only:

var e = new CustomDrawnElement(UITableViewCellStyle.Default, "myKey");

I am currently using the latest Xamarin Studio 3.

I have read every question regarding this class and no one seems to have had this problem. Not sure if it is due to the new 3 release that introduced a new bug.


Solution

  • Ok, after much research, I found the answer. In order for the custom height methods to be called, you need to set UnevenRows = true on the rootElement created for MonoDialog.