0

How do we find the default height of a control in Xamarin Forms? Say for example we have an entry for which Height & Width is not mentioned in the XAML.

  • When this is run on all 3 OS, what's the height of this entry?
  • Which unit does XF uses for height?
  • Will it be different on all 3 platforms?
Klors
  • 2,665
  • 2
  • 25
  • 42
Supreet
  • 831
  • 1
  • 9
  • 30

1 Answers1

0

You could use VisualElement.Height to get the Height of the element.

With regards to your questions:

When this is run on all 3 OS, what's the height of this entry?

Due to the fact height is allocated depending on its bounds, there is no default height of a control it will just fill its boundes depending on the LayoutOptions

Which unit does XF uses for height?

I think they use dpx although I can't find any links to back this but I will keep searching

Will it be different on all 3 platforms?

This will not only be different for every OS this could be different for every device because as I explained the height is determined from the bounds of the control

The Height of an element depends on its bounds in the same way Xaml works for WPF

This WPF article explains height within grids

JKennedy
  • 18,150
  • 17
  • 114
  • 198
  • VisualElement.Height & HeightRequest both have a default value of -1. I will look into that Grid Layout blog you shared to figure if we can find the height. Thanks – Supreet Oct 19 '15 at 13:42
  • @Supreet Untill the page is rendered the value will be `-1` as you mentioned. As soon as the `page` is rendered the control can work out its height and it will have a distinct value in that property – JKennedy Oct 19 '15 at 13:44
  • Here is a very simple POC if someone would like to try their hands. https://github.com/supreettare/XFControlHeightDemo – Supreet Oct 19 '15 at 13:47
  • so which event are we looking at? that confirms the page has been rendered? Will try adding a button click & see if the entry height has changed by this time. – Supreet Oct 19 '15 at 13:48
  • put your `entryheight.Height.ToString()` after `InitializeComponent` in the main `constructor` of the `page` – JKennedy Oct 19 '15 at 13:51
  • That's still -1 but I can see a value on click handler of a button. 74 for an entry in case of a Windows Phone. Will continue finding more.. – Supreet Oct 19 '15 at 13:54