Xamarin Vertical align a Label within a Grid Cell

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.


Published at

Tags: Xamarin

Luke Alderton

Comments

Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Tags
Latest Comments
By WilliamZon on MVC forms in Umbraco
12 Dec 2018, 09:34 AM
By Jamessobia on MVC forms in Umbraco
11 Dec 2018, 13:17 PM
By Andrewjek on Umbraco Get Current Member or Member By ID
10 Dec 2018, 17:27 PM
By Nigad42 on MVC forms in Umbraco
10 Dec 2018, 09:41 AM
By Robertflose on MVC forms in Umbraco
9 Dec 2018, 10:31 AM
By Otutu90 on Displaying text on a 16x2 LCD screen with a Raspberry Pi
9 Dec 2018, 01:58 AM
By Dufox53 on Moving SQL Server System Tables
8 Dec 2018, 22:12 PM
By Tepul31 on Moving SQL Server System Tables
8 Dec 2018, 21:48 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development