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 AEndumpbub on Reducing Umbraco memory usage by enabling 32-bit applications
13 Oct 2018, 07:04 AM
By nseo-sw.men on MVC forms in Umbraco
12 Oct 2018, 11:30 AM
By JM on Solved: You need to use a Theme.AppCompat theme (or descendant) with this activity
10 Oct 2018, 13:36 PM
By praveen on Xamarin Forms - Working with threads
5 Oct 2018, 12:05 PM
By Jasonced on MVC forms in Umbraco
27 Sep 2018, 05:41 AM
By Евгения on MVC forms in Umbraco
27 Sep 2018, 02:47 AM
By Wokeq62 on Using SQL DataTables to speed up database performance
25 Sep 2018, 17:28 PM
By AnubisMus on MVC forms in Umbraco
24 Sep 2018, 16:54 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development