Reputation: 914
I have a StackLayout (vertical options is Start). I need to add a view to it and after that to get height of StackLayout. How can I do that? Now after adding a view into StackLayout in code behind I get Height property equals 0.
Upvotes: 4
Views: 7588
Reputation: 914
I added a view into stacklayout like this
StackLayout currentColumn = columns.ElementAt(currentColumnIndex);
currentColumn.Children.Add(orderCard);
And wanted to get currentColumn.Height
, but it was 0.
Instead I used Measure
and that gave a correct Height
SizeRequest columnSizeRequest = currentColumn.Measure(OrdersContainer.Width / 5, OrdersContainer.Height);
Upvotes: 3
Reputation: 5370
In what part of code you are trying to get the size? It will not work if you check it in constructor or right after you add the view. What you can do in constructor is:
layout.SizeChanged += Layout_SizeChanged;
and then you will get correct size
private void Layout_SizeChanged(object sender, EventArgs e)
{
var h = layout.Height;
}
Upvotes: 9