Xamarin Vertical align a Label within a Grid Cell

« Back to list of posts

Some people have had trouble vertical aligning text tot he center of a Xamarin Foms Grid Cell, the answer is to add three simple attributes.

The Fix:

Apply the following to the Label in question and it should center vertically within the cell:

Center the Label horizontally:

HorizontalOptions = LayoutOptions.Center

Center the Label vertically:

VerticalOptions = LayoutOptions.FillAndExpand

Center the Label Text vertically:

VerticalTextAlignment = TextAlignment.Center

And that's it, the Label should now vertically align to the center of its parent.

Note: Xamarin has recently replaced YAlign with VerticalTextAlignment, so keep an eye out for that.


By Luke Alderton at 8 Jan 2017, 10:23 AM

Tags: Xamarin

Comments


Post a comment

Please correct the following:
Share with