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 Luke on Auto/Custom height on Xamarin Forms WebView for Android and iOS
15 Jun 2018, 09:43 AM
By vikki on Auto/Custom height on Xamarin Forms WebView for Android and iOS
14 Jun 2018, 13:35 PM
By jimbo on JQuery Unobtrusive Validation for dynamically created elements
13 Jun 2018, 17:13 PM
By ScottKem on MVC forms in Umbraco
8 Jun 2018, 10:29 AM
By Alaa on java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
3 Jun 2018, 20:16 PM
By Robertfrold on MVC forms in Umbraco
3 Jun 2018, 12:11 PM
By Kiran Lad on How to add a Xamarin Forms Loading Screen/Overlay
29 May 2018, 06:39 AM
By jake on Xamarin forms - Stop/Cancel back button event
26 May 2018, 15:24 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development