Moved from https://bugzilla.xamarin.com/show_bug.cgi?id=49311
I've confirmed this issue. I also confirmed the Label is sized full width, and this issue is still present with Fast Renderers.
From original Bugzilla description:
It's a bit odd, but sometimes the alignment of a Label inside a StackLayout inside a Frame (inside a ViewCell) is messed up.
If you scroll, then sometimes the Label is not centered and sometimes it's centered.
Text should be always centered on the screen
Text occasionally appears left aligned when scrolled.
https://github.com/lhaussknecht/CenterBug/blob/master/assets/centerBug.gif
https://www.dropbox.com/s/z4hzr7rl9o2lvqb/Screenshot%202017-12-18%2009.04.09.png?dl=0
https://www.dropbox.com/s/evk3zhdu0ivfi5p/Screenshot%202017-12-18%2009.23.53.png?dl=0
Maybe related with #1396
This issue is still happening with v2.5.0.280555. Is this has been resolved ? What is the work around ?
FYI: It isn't just when scrolled. If you are in a view (Page
) and you navigate forward and back... there's a 50:50 change the Label
will left-justify again.
So this sort of shows the approach you have to take. You can't try to color or expand the labels themselves because they always want to shift to the left. Just accept they are going to be left-justified.
You have to nest the Label
in a Grid
then manipulate the Label
as an object and not the text of the label. An then center the label
_inside_ the grid. If you want to change the background color: Don't. Color the grid the label is in.
Here we see the Label
as fushcia for ease of understanding. Imagine it transparent and you can see what the final result will look like. The Label
gets centered instead of being expanded and then trying to center the text.
This issue also applies for the VerticalTextAlignment
Another instance of this issue. When I exit the app on android and come back, it resets left.
https://www.screencast.com/t/SDvfVjjaMXD8
This is on 3.0.0.446417
iOS is fine.
@numb3r Someone posted a workaround on StackOverflow that works for me here
tlhintoq, your solution works for me
Most helpful comment
FYI: It isn't just when scrolled. If you are in a view (
Page
) and you navigate forward and back... there's a 50:50 change theLabel
will left-justify again.Workaround
So this sort of shows the approach you have to take. You can't try to color or expand the labels themselves because they always want to shift to the left. Just accept they are going to be left-justified.
You have to nest the
Label
in aGrid
then manipulate theLabel
as an object and not the text of the label. An then center thelabel
_inside_ the grid. If you want to change the background color: Don't. Color the grid the label is in.Here we see the
Label
as fushcia for ease of understanding. Imagine it transparent and you can see what the final result will look like. TheLabel
gets centered instead of being expanded and then trying to center the text.