Custom Layout, override OnSizeRequest bug?

CristinaBirkel.2642CristinaBirkel.2642 USMember
edited August 2014 in Xamarin.Forms

I've created a custom layout called HorizontalWrapLayout, which subclasses Layout, and have overridden OnSizeRequest. I seem to be getting strange behavior...

I return this line:
return new SizeRequest(new Size(widthRequest, heightRequest), new Size(minWidthRequest, minHeightRequest));

Stepping through the debugger, I see the following values for those local variables:

widthRequest: -1
minWidthRequest -1
heightRequest: 92
minHeightRequest: 44

Width is working fine, and I don't mean to be requesting anything in particular here, so feel free to ignore that part. The part I am interested in is the height. It seems like minHeightRequest is having an affect on the rendered height of the element, even when it's less than the heightRequest. Does that make any sense? 92 is the height that I want here. I've experimented with different values for minHeightRequest, and notice that when I set minHeightRequest to 1, the rendered element is shorter than when I set minHeightRequest to 80. I either have a misunderstanding of how heightRequest and minHeightRequest are supposed to be used, (I assume that the caller will take the max of the two??,) or else there might be a bug here. Can someone please help to shed some light? If you need a code example I could work on one, but it's totally just tangled up in my app right now and would take some time to put together.



Best Answer


  • CristinaBirkel.2642CristinaBirkel.2642 USMember
    edited August 2014

    Thanks for the answer!

    I find this to be counter-intuitive. Maybe it's just me, but MinimumHeightRequest says to me, "this is the minimum that the height should ever be." I have a use case where I want the layout to be whatever size it needs to be, but to also always be at least 44 tall. (So that the user can easily click on it, based on iOS UI guidelines.) I can certainly write this into the custom layout. I can also see MaximumHeightRequest being useful, and honestly I'd name the current one MaximumHeightRequest, and the missing one to be MinimumHeightRequest.

  • MitchMilamMitchMilam USMember ✭✭✭

    Yes, not very intuitive at all. It took me about 30 minutes to figure out what was happening.

  • PaulFrostPaulFrost USMember

    Having worked with Xamarin for 5 months now, the biggest and most frustrating problem I have experienced is the lack of support for useful dynamic sizing functionality. For a cross platform, multi screen size software this is very problematic. At the bare minimum Xamarin should include Minimum and Maximum Height/WidthRequests. It seems like a small request that would dramatically improve UI layout flexibility.

Sign In or Register to comment.