Forum Xamarin.Forms

Determine logical View's size?

ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭
edited July 2017 in Xamarin.Forms


How do I determine what space a View requires?

For example:

<Label Text="Lorem ipsum dolor sit amet" />

What will be this Label's size without knowing anything about its parents.
Now same question about a Cell, Panel or anything, consisting of a set of multiple controls, how can I recursively determine the size it requires (by requires I mean its minimum height in order to display its contents on screen without chopping it off).


  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭

    In WPF/UWP it's called ActualHeight, is there a Xamarin counterpart of that?

  • HunumanHunuman GBMember ✭✭✭✭

    Hi @ShimmyWeitzhandler

    There are some new device aware size conversion tools in the Skia# Forms.
    Not sure they do exactly what you are looking for, but could be worth having a look.

    Hope this helps


  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭

    @Hunuman it would have helped if I started my project in Skia# in first place...

  • DavidDancyDavidDancy AUMember ✭✭✭✭

    @ShimmyWeitzhandler can you elaborate a bit more on why you want to do this? These calculations are built in to Xamarin.Forms and it's usually not necessary to know the actual values that they calculate.

  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭

    The current reason I want this is, I have a ListView, and I want to make it size to its elements. The problem is I don't know the element size.

    I created this behavior that works well, but it doesn't measure the sizes of the elements.
    As a temporary workaround, to measure the elements (in HasUnevenRows) I apply the template to each of the items. When the rows are even I'd only measure the size once.
    I can cache the results so items processed are skipped, but I don't think this is the right way to go anyway, so I left it like it is as a temporary hack.

Sign In or Register to comment.